JAVASCRIPT » Email Scripts

  Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg

Email Validation script


This nice and simple script that 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:

      

</script type="text/javascript">

/***********************************************
* Email Validation script- © EPSILONSYS (www.Navioo.com)
* This notice must stay intact for legal use.
* Visit http://www.Navioo.com/ for full source code
***********************************************/

 

function checkmail(fld)
{ // simple email check
if(!fld.value.length||fld.disabled) return true; // blank fields are the domain of requireValue
var phony= /@(w+.)*example.(com|net|org)$/i;
if(phony.test(fld.value))
{ alert( 'Please enter your email address in the email field.'); return false; }
var emailfmt= /^w+([.-]w+)*@w+([.-]w+)*.w{2,8}$/;
if(!emailfmt.test(fld.value))
{ alert( 'The email field must contain a valid email address.');return false; } alert("email valid");
return true;
}

</script><form>
<input name="myemail" style="width: 270px;" type="text"> <input onclick="return checkmail(this.form.myemail)" value="Submit" type="submit">

</form >

 

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

  • admin@mydomain.com
  • jason+ajaxang@yahoo.com
  • auto@bbc.co.uk
  • mike@mydomain.ca
  • edward@12.24.16.345


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

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

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

</form>

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.


Free   Version: n/a   Platform(s): All   Updated:  July 21, 2008

Developer:EPSILONSYS Demo Download  
Rated by: 1 user(s)  
Follow Navioo On Twitter

Submit a resource