Solved

email verification-format

Posted on 2006-07-07
10
245 Views
Last Modified: 2006-11-18
Here is what I have to check the format of the email:var ptn_email=/^\s*\w+([\.\w\-]+)*\w@\w((\.\w)*\w+)*\.\w{2,}\s*$/;\
And it all seemed to work, but I entered an email in this format    here@there-again.biz    and I recieved error message saying email is incorrect please check and correct it. The - sign is putting a wrench in the works. How can I correct?
0
Comment
Question by:tarakwar101
10 Comments
 
LVL 29

Expert Comment

by:TeRReF
Comment Utility
ptn_email=/^\s*\w+([\.\w]+)*\w@\w((\.\w)*\w+)*\.\w{2,}\s*$/;\

Did you try this already?
0
 

Author Comment

by:tarakwar101
Comment Utility
Also since I am here, when people enter the phone numbers the format is (555)555-5555, if they don't enter the ( ) brackets they get an error is there a way to have them enter or not enter the brackets and not get an error? I dont care if the phone is in this format 555-555-555 or with the brackets but not 5555555555 or 555-5555 they must have the area code. Here is what I am using:
 var ptn_phone=/^\s*(\(\d{3}\)\s*)\d{3}\-\d{4}\s*$/;
0
 

Author Comment

by:tarakwar101
Comment Utility
That is the same code I am using currently?
0
 

Author Comment

by:tarakwar101
Comment Utility
I don't see any difference in your code then mine?
0
 

Author Comment

by:tarakwar101
Comment Utility
Problem is I am not sure how the code is broken down /^ <--don't know what that does? along with the others [\, or the W or {2}?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:tarakwar101
Comment Utility
Site is live and a user is entering the email address with the - sign, which is a legit email address. I upped the pts.
0
 

Assisted Solution

by:MARTINDELAGE
MARTINDELAGE earned 125 total points
Comment Utility
I suggest you use :

function checkEmail($email)
{      
  $user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+';
  $domain = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+';
  $ipv4 = '[0-9]{1,3}(\.[0-9]{1,3}){3}';
  $ipv6 = '[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}';

  return preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $email);
}

This function is bulletproof ;)
0
 
LVL 29

Accepted Solution

by:
TeRReF earned 250 total points
Comment Utility
Wow :)

A little less comprehensive:
if( !preg_match( \"/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/\", $email))
  // false
else
  true

For the phone number:
if (!preg_match('/^\(*\d{3}\)*-*\d{3}\-\d{4}$/', $phone2))
  // false
else
  // true



0
 
LVL 9

Assisted Solution

by:tolgaong
tolgaong earned 125 total points
Comment Utility
$email="tolga@yahoo.com"; // match
$email="tolga@yahoo.co.uk"; // match
$email="tolga@yahoo.co.k"; // not match
$email="tolga@yahoo.co."; // not match

if (preg_match('/^(?:[a-z0-9-_]+)@(?:[a-z0-9-_]+)\\.(?:[a-z]{2,3}(?:\\.[a-z]{2})?)$/', $email)) echo "mail is ok";
else echo "error in mail";
0
 

Author Comment

by:tarakwar101
Comment Utility
All the answers were excellent, but awarded extra pts toTeRRef for the added ph# format. Thanks all.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now