Validate that Email Text

[Total: 0    Average: 0/5]

This will validate an email address against know rules.

Head Code:

<script> 

function validate_form ( ) 
{ 
var valid = true; 
if ( document.info.name.value == "" ) 
{ 
alert ( "Your Name Is Missing." ); 
valid = false; 
} 
return valid; 
} 

function emailCheck (emailStr) { 
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>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; 
}
return true;
} 

var counter=0; 
function isReady() {
var _ret=false;
if (validate_form())
  _ret=true;
if(emailCheck(document.info.email.value))
  _ret=true;
else
  _ret=false;
if(_ret)
  if(counter++)
  {
    _ret=false;
    alert('The Form Is Already Being Submitted'); 
  }
  else
    _ret=true;
alert(_ret);
return _ret; 
} 
</script> 

Body Code:

<form name=info onSubmit="return(isReady())"> 
N:<input type=text name=name size="20"> 
E:<input type=text name=email size="20"> 
<input type=submit name=submit> 
</form> 

Times Viewed: 8

Leave a Reply

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