JavaScript Email Validation

Internet addresses can be tricky things for users, especially new users, to type. You can help them by scanning the email address they enter and checking it for inproper form.

This script validates an email address with Regular Expressions

 

Example

Email Address:

 

Script Source

<Under the head section>

<script language="javascript" type="text/javascript">

<!-- Hide from old browsers

re = /^\w+([\.-]?\w+)*@\w+([\.-]?w+(\.\w{2,3})+$/

function submitIt(myForm) {
if (re.test(myForm.emailAddr.value)) {
return true
}
alert("Invalid email address")
myForm.emailAddr.focus()
myForm.emailAddr.select()
return false
}

// Script by www.wizzardweb.co.uk
// If you are using this code please leave a link to www.wizzardweb.co.uk
// End hiding script -->
</script>

<Under the body section>

<form onsubmit="return submitIt(this)" action="#">
<table border="0" cellspacing="8" cellpadding="8">
<tr>
<td align="right" valign="top">
Email Address: </td>
<td>
<input name="emailAddr" type="text" size="50" />
<p><input type="reset" />&nbsp;<input type="submit" value="Submit" /></p> </td>
</tr>
</table>
</form>

 

Please let me know if this script was helpful to you.

[rating]