Solved

email verification-format

Posted on 2006-07-07
10
248 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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 125 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 250 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 125 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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.

739 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