Simple Email Validation using Javascript regex

The following is the source code for a simple email validation using JavaScript regular expression.

    var email = document.getElementById('emailaddress');
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email.value)) {
        alert('Please provide a valid email address');
        email.focus;
        return false;
    }

Do share your thoughts and comments.

Leave a Reply

Your email address will not be published. Required fields are marked *