Top email-validation Questions

List of Tags

How can an email address be validated in Javascript?

Though this solution may be simple, I'm sure this is one of those useful things that people will be Googling for and deserves its own entry on the site

Answered By: sectrean ( 475)

Using Regular Expressions is probably the best way. Here's an example (live demo):

function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\
    return re.test(email);

But keep in mind that one should not rely only upon JavaScript validation. JavaScript can easily be disabled. This should be validated on the server side as well.