Verify an email address on your web site

From The IT Community
Jump to: navigation, search




When your website asks for an email address in a form, it seems professional to first check if the address is valid.


Here is how to verify an email address on your web site:


Put the following in the <head> part of your web site:

 <SCRIPT LANGUAGE="JavaScript">
 <!--
 function checkEmail() {
  text=document.emailform.email.value;
  if (text.indexOf("@")<3){
    alert(" This email address seems wrong. Please"
    +" check the prefix and '@' sign.");
    return false;
  }
  if ((text.indexOf(".com")<5)&&(text.indexOf(".org")<5)
    &&(text.indexOf(".gov")<5)&&(text.indexOf(".net")<5)
    &&(text.indexOf(".co.uk")<7)&&(text.indexOf(".at")<4)
    &&(text.indexOf(".de")<4)&&(text.indexOf(".edu")<5))
  {
     alert(" This email address seems wrong. Please"
     +" check the suffix. (It should include a .com, .edu,"
     +" .net, .org, .gov, .co.uk, .at or .de)");
     return false;
  }
 return true;
 }
 //-->
 </SCRIPT>


This script checks if the address is valid. Of course, you will want to modify it to check for other prefixes and such.


And now, to make the form appear, put the following into the <body> part of your website:

 <CENTER>
 <FORM NAME="emailform" ACTION="email.html"
 onSubmit="return checkEmail()">
  <INPUT TYPE="text" NAME="email" SIZE=40 VALUE=""><BR>
  <INPUT TYPE="submit" NAME="email1" VALUE="Submit">
 </FORM>
 </CENTER>

The file email.html is what shows up when a valid address has been entered.



Was this article helpful? Then please donate to keep The IT Community alive...

If you found this article helpful please share it, comment and help others by writing your own article.






Translate this page:




Articles found in the same category:
(max. 20 shown)