You should try try this script which uses regular expressions to verify that a form field contains a legal email address.
Look here for some examples of legal email addresses that this script will identify:
â¢
[email protected]
â¢
[email protected]
â¢
[email protected]
â¢
[email protected]
â¢
[email protected]
â¢
[email protected]
Guide 1: Insert the underneath script to the <BODY> section of your web page:
Code:
<script type="text/javascript">
/***********************************************
* Email Validation script
* This notice must stay intact for legal use.
***********************************************/
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}
</script>
<form>
<input name="myemail" type="text" style="width: 270px"> <input type="submit" onClick="return checkmail(this.form.myemail)" value="Submit" />
</form>
The code on top includes a example form where this script validates the email field contained. The form looks similar to this:
Code:
<form>
<input name="myemail" type="text" style="width: 300px"><br/>
<input type="submit" onClick="return checkmail(this.form.myemail)" value="Submit" />
</form>
To modify this script to serve up your own form, just change the parts in bold above to your own. More purposely, you first give your email address field a name(like name="myemail"). Then, adjust the submit button of the form by adding in the "onClick" part. keep in mind to alter "myemail" to replicate the name of your email address field.