Solved

email verification-format

Posted on 2006-07-07
10
247 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
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Split wordpress loop 35 56
Need to remove %20 from url in get 17 36
How to make a good PHP + MySQL + JS pagination system? 3 34
Inserting data into database 10 36
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 …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

828 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