//****************************************************************** // Form Validation Goodness // //****************************************************************** function validateForm(deForm) { with (deForm) { if (IsEmpty(usr_name)) { alert("Please key in your name"); usr_name.focus(); return false; } else if (!IsValidEmail(usr_emailaddress)) { alert("Please check your email address again"); usr_emailaddress.focus(); return false; } else if (IsEmpty(usr_residential)) { alert("Please key in your residential address"); usr_residential.focus(); return false; } else if ( (!IsNumeric(usr_areacode)) || (IsEmpty(usr_areacode)) ) { alert("Please key in a valid area code"); usr_areacode.focus(); return false; } else if ( (!IsNumeric(usr_phonenumber)) || (IsEmpty(usr_phonenumber)) ) { alert("Please leave us your phone number (without spaces and hyphens)"); usr_phonenumber.focus(); return false; } return true; } } //Form Validation Funcs // Global Functions function radioVal(obj) { var retVal; for (var i=0;i= "A") && (ch <= "Z")) || ((ch >= "a") && (ch <= "z")) || (ch == " ") || (ch == "-") || (ch == "'") || (ch == ".") || (ch == "(") || (ch == ")") || (ch == ",")) IsAlpha= true; else return false; } return IsAlpha; } function IsNumeric(szFieldName) { var i; var IsNum; var ch; IsNum=true; TrimField(szFieldName); for(i=0; i= "0") && (ch <= "9")) IsNum= true; else return false; } return IsNum; } function IsDecimal(szFieldName) { var i; var IsDec; var ch; IsDec=true; TrimField(szFieldName); for(i=0; i= "0") && (ch <= "9")) IsDec= true; else if (((ch == ".") || (ch == ",")) && (i>0) && (i= "0") && (ch <= "9")) IsNum=true; else { if ( ch=="(" || ch==")" || ch=="-" || ch==" " ) IsNum=true; else return false; } } return IsNum; } function IsTelcoNumSG(szFieldName,prefix,numlen) { var i; var IsNum; var ch; var nl; IsNum=true; TrimField(szFieldName); nl = 0; for (i=0; i= "0") && (ch <= "9")) { IsNum=true; nl++; } else { if ( ch=="(" || ch==")" || ch=="-" || ch==" " ) IsNum=true; else return false; } } if (nl != numlen) return false; return IsNum; } function IsValidEmail(szFieldName) { var IsEmail; var ch; var checkAT; var checkPERIOD; var checkExt; checkAT = 0; checkPERIOD = 0; if (IsEmpty(szFieldName)) return false; if (szFieldName.value.indexOf("@")==-1) return false; if (szFieldName.value.indexOf("@")==0) return false; if (szFieldName.value.indexOf("@")>=40) return false; if ((parseInt(szFieldName.value.length) - szFieldName.value.indexOf("@"))>=40) return false; if (szFieldName.value.indexOf("@")==(parseInt(szFieldName.value.length)-1)) return false; if (szFieldName.value.indexOf(" ") != -1) return false; if ((szFieldName.value.indexOf(".com")==-1) && (szFieldName.value.indexOf(".net")==-1) && (szFieldName.value.indexOf(".us")==-1) && (szFieldName.value.indexOf(".biz")==-1) && (szFieldName.value.indexOf(".edu")==-1) && (szFieldName.value.indexOf(".info")==-1) && (szFieldName.value.indexOf(".tv")==-1) && (szFieldName.value.indexOf(".org")==-1) && (szFieldName.value.indexOf(".cc")==-1) && (szFieldName.value.indexOf(".gov")==-1) && (szFieldName.value.indexOf(".fm")==-1) && (szFieldName.value.indexOf(".co")==-1)) return false; for(i=0; i= 2) { IsEmail = false; break; } } if (ch == ".") { checkPERIOD = checkPERIOD + 1; } if ((( ch >= "A") && (ch <= "Z")) || ((ch >= "a") && (ch <= "z")) || ((ch >= "0") && (ch <= "9")) || (ch == "$") || (ch == "-") || (ch == ".") || (ch == "&") || (ch == "+") || (ch == "!") || (ch == "*") || (ch == "`") || (ch == "(") || (ch == ")") || (ch == ",") || (ch == "@") || (ch == "_")) { IsEmail= true; } else { IsEmail= false; break; } } if (checkPERIOD == 0) { return false; } if (!IsEmail) { return false; } return true; } function TrimField(szFieldName) { var szNewStr; if (szFieldName.value != "") { szNewStr = TrimString(szFieldName.value); szFieldName.value = szNewStr; } } function TrimString(szString) { var i = 0; var j = 0; for (i=0; i i; j--) { if (szString.charAt(j) != " ") { break; } } break; } } if (i > j) i = j; if (szString.length > 0 && szString.charAt(j) != " ") j++; return szString.substring(i, j); } function lessChar(szFieldName,minNo) { TrimField(szFieldName); if (szFieldName.value == "") return true; if (parseInt(szFieldName.value.length) <= minNo) return true; return false; } function bfnIsDate (day,month,year) { var today = new Date(); year = ((!year) ? y2k(today.getYear()):year); month = ((!month) ? today.getMonth():month-1); if (!day) return false var test = new Date(year,month,day); if ( (y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()) ) return true; else return false } function y2k(number) { return (number < 1000) ? number + 1900 : number; } function chkTextLength(szFieldName, maxlength) { if (szFieldName.value.length > maxlength) { alert("Text exceeds max. allowed length of " + maxlength + " characters.\n\nTotal no. of characters : " + szFieldName.value.length); szFieldName.focus(); return false; } else return true; }