// JavaScript Document function trim(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g,""); } function ltrim(stringToTrim) { return stringToTrim.replace(/^\s+/,""); } function rtrim(stringToTrim) { return stringToTrim.replace(/\s+$/,""); } //for phone validation function phcheck(pnum) { var phchar="1234567890 -_+.()"; for (i=0;i<=pnum.length;i++) { if(phchar.indexOf(pnum.charAt(i))==-1) { alert("Only Numbers and (+-_. ) are allowed"); return false ; } } return true ; } function validate() { if(trim(document.contact.name.value)=="") { alert("Name must be filled out!"); document.contact.name.focus(); return false; } if(trim(document.contact.company.value)=="") { alert("Company must be filled out!"); document.contact.company.focus(); return false; } if(trim(document.contact.email.value)=="") { alert("Email must be filled out!"); document.contact.email.focus(); return false; } if(!echeck(document.contact.email.value)) { document.contact.email.value=""; document.contact.email.focus(); return false; } if(document.contact.phone.value=="") { alert("Telephone must be filled out!"); document.contact.phone.focus(); return false; } else if (document.contact.phone.value!="") { if(!phcheck(document.contact.phone.value)) { document.contact.phone.value=''; alert("Enter numbers only"); document.contact.phone.focus(); return false; } } if(trim(document.contact.comments.value)=="") { alert("Comment / Request must be filled out!"); document.contact.comments.focus(); return false; } return true; } function echeck(str) { var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1) { alert("Invalid email address") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) { alert("Invalid email address") return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) { alert("Invalid email address") return false } if (str.indexOf(at,(lat+1))!=-1) { alert("Invalid email address") return false } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) { alert("Invalid email address") return false } if (str.indexOf(dot,(lat+2))==-1) { alert("Invalid email address") return false } if (str.indexOf(" ")!=-1) { alert("Invalid email address") return false } return true; }