I have a requirement to validate an email address entered when a user comes out from the textbox.
I have googled for this but I got form validation JScript; I don\'t wa
You should use below regex which have tested all possible email combination
function validate(email) {
var reg = "^[a-zA-Z0-9]+(\.[_a-zA-Z0-9]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,15})$";
//var address = document.getElementById[email].value;
if (reg.test(email) == false)
{
alert('Invalid Email Address');
return (false);
}
}
Bonus tip if you're using this in Input tag than you can directly add the regex in that tag example
Above you can see two attribute required & pattern in
required make sure it input block have data @time of submit
&
pattern make sure it input tag validate based in pattern(regex) @time of submit
For more info you can go throw doc