?
Solved

email verification-format

Posted on 2006-07-07
10
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 29

Expert Comment

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

Did you try this already?
0
 

Author Comment

by:tarakwar101
ID: 17061487
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
ID: 17061509
That is the same code I am using currently?
0
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

Author Comment

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

Author Comment

by:tarakwar101
ID: 17061545
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
 

Author Comment

by:tarakwar101
ID: 17061855
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 500 total points
ID: 17062139
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 1000 total points
ID: 17062485
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 500 total points
ID: 17063956
$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
ID: 17074025
All the answers were excellent, but awarded extra pts toTeRRef for the added ph# format. Thanks all.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

762 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