Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 402
  • Last Modified:

email verification-phone verification format

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?

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 here@there-somewhere.biz and the - gives error!

0
tarakwar101
Asked:
tarakwar101
1 Solution
 
ZvonkoSystems architectCommented:
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;


0
 
NushiCommented:
what do you have this at the end?
w{2,}

0
 
ZvonkoSystems architectCommented:
For the phone perhaps something like this:

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




0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

0
 
Jens FiedererTest Developer/ValidatorCommented:
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:
^\s*\w+([\.\w\-]+)*\w@\w((\.\w)*[\w-]+)*\.\w{2,}\s*$
would validate your example.
0
 
Jens FiedererTest Developer/ValidatorCommented:
Sorry, let that one age a bit, and then posted without checking whether somebody had already answered.

Just ignore me
0
 
tarakwar101Author Commented:
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 '/'
0
 
Pravin AsarPrincipal Systems EngineerCommented:
Here is a  example code for you.

<html>
<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;
     return(email.test(value));
}

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

function formValidate (theForm) {
     if (!isEmail(theForm.email.value)) {
     alert ('Invalid Email Address');
        return false;
     }
     if (!isPhone(theForm.phone.value)) {
     alert ('Invalid Phone Number');
        return false;
     }
     return true;
}
</script>
<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">
</form>
</html>
0
 
ZvonkoSystems architectCommented:
Sorry, my fault.

Check this:

<script>

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

alert(ptn_email.test("here@there-somewhere.biz"));

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

alert(ptn_phone.test("(555)5555-5555"));

</script>




0
 
ZvonkoSystems architectCommented:
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*$/;


0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now