Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

email verification-format

Posted on 2006-07-07
10
Medium Priority
?
255 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
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!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

604 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