How to validate an email address in JavaScript?

Can someone please let me know whether using a regular expression is the best way to validate an email in JavaScript? If so please let me know the best RegEx to do this.


  • You can use a regular expression to validate. But please note that you cannot find a regular expression which will validate email addresses 100%. You should use a validation method like confirmation for a perfect validation.

    Following is a validation with a regular expression.

    function validateEmail(email) { 
        var emailRegEx = /^(([^<>()[\]\\.,;:\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 emailRegEx.test(email);
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion