Email Validator and Submit One Timer

[Total: 0    Average: 0/5]

This script shows how to do two things: validate email addresses, and restrict submission to one time.

Head Code:

<SCRIPT> 
function doupper(obj) 
{ 
obj.value=(((obj.value.substr(0,1)).toUpperCase())+obj.value.substr(1,obj.value.length)) 
} 

function emailCheck (_form)
{ 
 emailObj=_form.t1;
 emailStr = emailObj.value; 
 if(emailStr == "") 
 { 
   alert ( "Please fill in the 'Your Name' box." ); 
   return false; 
 } 
 var checkTLD=0; 
 var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; 
 var emailPat=/^(.+)@(.+)$/; 
 var specialChars="\(\)><@,;:\\\"\.\[\]"; 
 var validChars="[^\s" + specialChars + "]"; 
 var quotedUser="("[^"]*")"; 
 var ipDomainPat=/^[(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})]$/; 
 var atom=validChars + '+'; 
 var word="(" + atom + "|" + quotedUser + ")"; 
 var userPat=new RegExp("^" + word + "(\." + word + ")*$"); 
 var domainPat=new RegExp("^" + atom + "(\." + atom +")*$"); 
 var matchArray=emailStr.match(emailPat); 
 if (matchArray==null)
 { 
  alert("The Email Address Is Invalid"); 
  return false; 
 } 
 var user=matchArray[1]; 
 var domain=matchArray[2]; 
 for (i=0; i<user.length; i++)
 { 
  if (user.charCodeAt(i)>127)
  { 
   alert("The Username Contains Invalid Characters."); 
   return false; 
  } 
 } 
 for (i=0; i<domain.length; i++) 
 { 
  if (domain.charCodeAt(i)>127)
  { 
   alert("Ths Domain Name Contains Invalid Characters."); 
   return false; 
  } 
 } 
 if (user.match(userPat)==null) 
 { 
  alert("The Username Is Invalid."); 
  return false; 
 } 
 var IPArray=domain.match(ipDomainPat); 
 if (IPArray!=null)
 { 
  for (var i=1;i<=4;i++) 
  { 
   if (IPArray[i]>255) 
   { 
    alert("The Destination IP Address Is Invalid."); 
    return false; 
   } 
  } 
  return true; 
 } 
 var atomPat=new RegExp("^" + atom + "$"); 
 var domArr=domain.split("."); 
 var len=domArr.length; 
 for (i=0;i<len;i++) 
 { 
  if (domArr[i].search(atomPat)==-1) 
  { 
   alert("The Domain Name Is Invalid."); 
   return false; 
  } 
 } 
 if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
 { 
  alert("The Domain Name Extension Is Invalid"); 
  return false; 
 } 
 if (len<2) 
 { 
  alert("The Address Is Missing A Hostname."); 
  return false; 
 } 
 /*
  * This return-true was added by Vic Phillips on Feb-2006
  */
 return true;
} 
var SUB_YET=0; /* this keeps it from ever submitting after the first time*/
</SCRIPT> 

Body Code:

Enter a valid email address (for verification only - not sent anywhere)
<form name="info" onSubmit="return emailCheck(this)&&!(SUB_YET++)"> 
<input type=text name=t1>
<input type=submit value="Check the email to see if it is valid">
</form>

Times Viewed: 7

Leave a Reply

Your email address will not be published. Required fields are marked *