NS6+ IE5+ Opera 7+

Email Validation script

Author: Dynamic Drive

Description: This script uses regular expressions to check that a form field contains a valid email address. Note that it won't catch all invalid emails, like most similar scripts. However, for most intents and purposes, this script should serve its purpose well, by rejecting common email typos while leaving room for obscure yet valid emails to pass.

Here are some examples of valid email addresses that this script will recognize:

  • contact@mydomain.com
  • jason+lang@gmail.com
  • help@nbc.co.uk
  • mary.k.ashley@celeb.com
  • george@sub.whatever.mydomain.ca
  • edward@

Note: If you discover a valid email address that this script rejects, please let us know.

Demo: Try typing in an email address below:

Directions: Developer's View

Step 1: Add the below script to the <BODY> section of your page:

Select All

The code above includes a sample form where this script validates the email field contained. The form looks like this:

<input name="myemail" type="text" style="width: 300px"><br/>
<input type="submit" onClick="return checkmail(this.form.myemail)" value="Submit" />

To customize this script to serve your own form(s), simply change the parts in red above to your own. More specifically, you should first give your email address field a name(ie: name="myemail"). Then, modify the submit button of the form by adding in the "onClick" portion. Remember to change "myemail" to reflect the name of your email address field.

Wordpress Users: Step by Step instructions to add ANY Dynamic Drive script to an entire Wordpress theme or individual Post