How to validate an email address in JavaScript? - Programmers Heaven

Howdy, Stranger!

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


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to validate an email address in JavaScript?

NickFNickF USAPosts: 132Member

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.



  • DavidMDavidM USAPosts: 342Member

    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.