How to validate email address
08
June
2013

Include the following javascript in your page’s head section

<script type="text/javascript">
function validatedata()
{
var mail = document.frmContact.txtemail;

if((mail.value == "") || (mail.value == ""))
{
alert("Please Enter Email Address");
mail.focus();
return false;
}

var filter1 = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter1.test(mail.value))
{
alert("Provide valid email address");
mail.focus();
return false;
}

}
</script>

Now place the Following Code in your body section.

<form name="frmContact" method="post" onsubmit="return validatedata();">
<table cellpadding="0" cellspacing="0" align="center">
<tr>
<td>Enter Your Email Address</td>
<td><input type="text" name="txtemail" id="txtemail"  />
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit Email" /></td>
</tr>
</table>
</form>

Run the page to test your email validation script.

You can Directly run the script from here.

  • 798 View
  • Pin It