.

Monday, June 9, 2008

Email Validation script

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.

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">

<-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.

No comments:

.