How to validate email id in javascript

Find the below code by which you can validate the email field using java-script on client side,

var reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;
if(!reg.test(document.getElementById(“email”).value)){
alert(“Please fill email address in correct format”);
document.getElementById(’email’).focus();
return false;
}

Share This Post

2 Responses to "How to validate email id in javascript"

Post Comment