Validate email in JavaScript?


This is one of those useful things that people will be Googling for validate email address on Javascript, this tutorial mostly used when you are developing app on Cross platform, like sencha, phonegap.

function validateEmail(email) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);

}

Here, Using regular expressions is probably the best way. Here's an example (live demo):


Happy Coding!!!
Validate email in JavaScript? Validate email in JavaScript? Reviewed by D Kshetri on 11:47 PM Rating: 5

No comments:

Powered by Blogger.