JS · February 21, 2017 0

Validating email using javascript

function validateEmail(email) {
    var re = /^(([^<>()[]\.,;:s@&quot;]+(.[^<>()[]\.,;:s@&quot;]+)*)|(&quot;.+&quot;))@(([[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 re.test(email);
}

Example

if (validateEmail(document.getElementById(&quot;email&quot;).value)) {
    alert('valid');
}