email verification-phone verification format

Posted on 2006-07-07
Last Modified: 2008-02-01
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    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?

Also the phone format gives an error if they do not enter the brackets aroung the area code (555), but I want them to be able to enter in this format (555)555-5555 or 555-555-5555 and not get the error.
I want them to get an error if they don't enter the area code 555-5555 or 55-555-5555<--missing digits? Need help, The site is live and I have an admin for the site entering an account for a user and they have the email address as and the - gives error!

Question by:tarakwar101
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
LVL 63

Expert Comment

ID: 17061890
Like this:

var ptn_email=/^\s*\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\w+)*\.[a-z]{2,}\s*$/i;

And I would not allow spaces before and after the email:

var ptn_email=/^\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\w+)*\.[a-z]{2,}$/i;

LVL 10

Expert Comment

ID: 17061902
what do you have this at the end?

LVL 63

Expert Comment

ID: 17061932
For the phone perhaps something like this:

var ptn_phone=/^\s*\(?\d{3}\)?[\-\ ]?\d{4}[\-\ ]?\d{4}\s*$/;

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

LVL 63

Expert Comment

ID: 17061948
The quantifier {2,} matchers minimum two preceeding elements but without upper limit.

LVL 23

Expert Comment

by:Jens Fiederer
ID: 17062099
Is that one format supposed to give you phone AND email?
I don't see how that expression can EVER validate something not containing a "@"

Anyway, to allow a "-" you can add it where the w's are:
would validate your example.
LVL 23

Expert Comment

by:Jens Fiederer
ID: 17062108
Sorry, let that one age a bit, and then posted without checking whether somebody had already answered.

Just ignore me

Author Comment

ID: 17062169
When I tested it gives error saying Expected '/' on line 55

var ptn_email=/^\s*\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\w+)*\.[a-z]{2,}\s*$/i;

Also i added a space after the email address to see if it generated error but it didn't so I am assuming it is because of the expected '/'
LVL 29

Expert Comment

by:Pravin Asar
ID: 17062332
Here is a  example code for you.

<script language="javascript">

function isEmail(value) {
     var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;

function isPhone(value) {
     var phone = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/;
// Usage example :

function formValidate (theForm) {
     if (!isEmail( {
     alert ('Invalid Email Address');
        return false;
     if (!isPhone( {
     alert ('Invalid Phone Number');
        return false;
     return true;
<form name="myform" onsubmit="return formValidate(this);">
<br>Email <input type="text" name="email">
<br>Phone <input type="text" name="phone">
<br><input type="submit" value="Submit">
LVL 63

Accepted Solution

Zvonko earned 500 total points
ID: 17062380
Sorry, my fault.

Check this:


var ptn_email = /^\s*\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.[a-z]{2,}\s*$/i;


var ptn_phone = /^\s*\(?\d{3}\)?[\-\ ]?\d{4}[\-\ ]?\d{4}\s*$/;



LVL 63

Expert Comment

ID: 17062449
Sorry, the phone format is 3-3-4,   I coded 3-4-4

Check this:

var ptn_phone = /^\s*\(?\d{3}\)?[\-\ ]?\d{3}[\-\ ]?\d{4}\s*$/;


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
PHP: Filling Out/Creating a PDF 29 108
jQuery Datatables.js Selecting a Row to get ID 5 37
JS to redirect to prev page 8 24
Building JSON/JQuery Results Display 11 27
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 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