// 3D PHP File Form-Mailer Check Form JavaScript Document

// This is an open-source form validation script. Form validation is called by the form tag onSubmit="return cf()" when the form is submitted. If everything checks out, the sendform.php gets called. You can use any form validation (e.g. strict or non-strict - this one is non-strict) or no validation at all. I use this non-strict code for my form-mailer with a semi-strict customer number line added. These comments can of course be deleted upon use.

function cf(){
if(document.mailform.firstname.value.length==0){alert("Please enter your first name.");
document.mailform.firstname.focus();return false}

if(document.mailform.lastname.value.length==0){alert("Please enter your last name.");
document.mailform.lastname.focus();return false}

if(document.mailform.Email.value.length==0){alert("Please enter your email address.");
document.mailform.Email.focus();return false}
if(isEmail(document.mailform.Email.value)==false){alert("Please enter a valid email address.");
document.mailform.Email.focus();return false}

if(document.mailform.company.value.length==0){alert("Please enter your company name.");
document.mailform.company.focus();return false}

if(document.mailform.jobtitle.value.length==0){alert("Please enter your job title.");
document.mailform.jobtitle.focus();return false}

if(document.mailform.phone.value.length==0){alert("Please enter your contact number.");
document.mailform.phone.focus();return false}

if(document.mailform.specify.value.length==0){alert("Please specify how did you find us.");
document.mailform.specify.focus();return false}
}

function isEmail(str){
var supported=0;
if(window.RegExp){
var tempStr="a";
var tempReg=new RegExp(tempStr);
if(tempReg.test(tempStr))supported=1}
if(!supported)
return(str.indexOf(".")>2)&&(str.indexOf("@")>0);
var r1=new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
var r2=new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
return(!r1.test(str)&&r2.test(str))}

