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;
}

Leave a reply

Connect With CodexWorld