How to validate an email address in JavaScript
// Html form call function name at submit button
<form name="form1" action="#">
<input type='text' name='text1'/>
<input type="submit" name="submit" value="Submit"
onclick="ValidateEmail(document.form1.text1)"/>
</from>
// Write the function name ValidateEmail below
<script>
function ValidateEmail(inputText)
{
var mailformat = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
if(inputText.value.match(mailformat))
{
alert("Valid email address!");
document.form1.text1.focus();
return true;
}
else
{
alert("You have entered an invalid email address!");
document.form1.text1.focus();
return false;
}
}
</script>