Email validation in JavaScript using Regular Expression

Email input field validation is mandatory before submitting the HTML form. Email validation helps to check if a user submitted a valid email address or not. Using regular expression in JavaScript, you can easily validate the email address before submitting the form. We’ll use the regular expression for validate an email address in JavaScript.

function validateEmail(email){
    var reg = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
    if(reg.test(email)){
        return true;
    }
    alert('Please enter valid email.');
    return false;
}

1 Comment

  1. Rahul Said...

Leave a reply

keyboard_double_arrow_up