function MainSearch(Field){ if (!ContainsSomething(Field)) { return false; } var Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@-." for (i=0; i < Field.value.length; i++) { var CheckChar = Field.value.charAt(i); CheckChar = CheckChar.toUpperCase(); if (Letters.indexOf(CheckChar) == -1 || Field.value.length<2) { Field.className='formerrors'; return false; } } Field.className='formok'; return true; } // Check for Numbers Only, function Number(Field) { if (!ContainsSomething(Field)) { Field.className='formerrors'; return false; } var digits = "0123456789"; for (var i = 0; i < Field.value.length; i++) { temp = Field.value.substring(i, i+1) if (digits.indexOf(temp) == -1 && Field.value != "") { Field.className='formerrors'; return false; break; } } Field.className='formok'; return true; } function returnSelection(radioField) { var selection = null; for (i=0; i < radioField.length; i++) { if (radioField[i].checked) { selection=radioField[i].value; return selection; } } return selection; } ////////////////////// Michael Added //////////////////////////// // http://www.phpwizard.net/validator/ //######### Drop down box and popup window ############################ // Check for more than 6 characters) Field function IsValidChars(Field) { if (!ContainsSomething(Field)) { return false; } if (Field.value.length<6) { return false; } else { return true; } } // Check for less than 3 characters) Field function IsValidChars3(Field) { if (!ContainsSomething(Field)) { return false; } if (Field.value.length<6) { return false; } else { return true; } } // Check if Field contains something function ContainsSomething(Field) { if ((Field.type == "text") || (Field.type == "textarea")) { if (Field.value == "") { Field.className='formerrors'; return false; } } else { if (returnSelection(Field) == null) { Field.className='formerrors'; return false; } } Field.className='formok'; return true; } ////////////////////// Michael Added //////////////////////////// // http://www.phpwizard.net/validator/ // Check for the minimum allowed password characters function IsValidPassword(Field) { if (Field.value.length<6) { Field.className='formerrors'; return false; } else { Field.className='formerrors'; return true; } } // Check for more than 6 characters) Field function IsValidUsername(Field){ if (Field.value.length<6) { Field.className='formerrors'; return false; } else { Field.className='formok'; return true; } } // Check that there are no funnies in the username function ValidUsername(Field){ if (!ContainsSomething(Field)){ Field.className='formerrors'; return false; } if (Field.value.indexOf("@")!=-1){ Field.className='formerrors'; return false; } else { Field.className='formok'; return true; } } //Check for valid Credit Amount, //Credit amount should be -0.00 function ValidCreditAmount(Field){ if (Field.value.indexOf("-")!=-1){ Field.className='formok'; return true; } else { Field.className='formerrors'; return false; } } // Check for valid Telephone Number, // and more than 8 characters) function IsTelephone(Field) { if (!ContainsSomething(Field)) { return false; } var Letters = "()+-0123456789 .,extEXT" for (i=0; i < Field.value.length; i++) { var CheckChar = Field.value.charAt(i); CheckChar = CheckChar.toUpperCase(); if (Letters.indexOf(CheckChar) == -1 || Field.value.length<8) { Field.className='formerrors'; return false; } } Field.className='formok'; return true; } // Check for valid 3 Digit Credit Card Code, function IsCardDigits(Field) { if (!ContainsSomething(Field)) { Field.className='formerrors'; return false; } var Letters = "0123456789" for (i=0; i < Field.value.length; i++) { var CheckChar = Field.value.charAt(i); CheckChar = CheckChar.toUpperCase(); if (Letters.indexOf(CheckChar) == -1 || Field.value.length -3) { Field.className='formerrors'; return false; } } Field.className='formok'; return true; } // Check for valid DOMAIN NAME function IsValidDomainName(Field) { if (!ContainsSomething(Field)) { return false; } if (Field.value.indexOf(".")==-1 || Field.value.indexOf(" ")!=-1 || Field.value.length<4) { return false; } else { return true; } } function ValidDomainName(Field) { if (!ContainsSomething(Field)) { Field.className='formerrors'; return false; } if (Field.value.indexOf(".")==-1 || Field.value.indexOf(" ")!=-1 || Field.value.length<4 || Field.value.indexOf("@")!=-1) { Field.className='formerrors'; return false; } else { return true; } } // Ignore stuff //======================================================================= ////////// Validate -[space]/ ////////////////////////////////////////////// function ignoreLots(str) { var out = "", flag = 0; for (i = 0; i < str.length; i++) { if ((str.charAt(i) != "-") && (str.charAt(i) != " ") && (str.charAt(i) != "/")) { out += str.charAt(i); flag = 0; } else { if(flag == 0) { out += ""; flag = 1; } } } return out; } //// \"this.value=ignoreLots(this.value);\" ////////////// ////////////////////////////////////////////////////////////////////////// /// Validate Check Boxes /////// //var notdone ="Choose"; //var done = "Selected"; //function checked_services (field) { //if (field.value.checked) { //field.value = done; //}else{ //field.value = notdone; // } //} ///////////////////////////////////////////////////////////////////////// function ConvertBR(input) { // Converts carriage returns // to
for display in HTML var output = ""; for (var i = 0; i < input.length; i++) { if ((input.charCodeAt(i) == 13) && (input.charCodeAt(i + 1) == 10)) { i++; output += "
"; } else { output += input.charAt(i); } } return output; } function ignoreSpaces(string) { var temp = ""; string = '' + string; splitstring = string.split(" "); for(i = 0; i < splitstring.length; i++) temp += splitstring[i]; return temp; } //////////////////////////////////////////////////////////////// // Check for valid (ie containg "@", ".", // and more than 6 characters) email-address in Field function IsValidEmail(Field) { if (!ContainsSomething(Field)) { Field.className='formerrors'; return false; } if (Field.value.indexOf("@")==-1 || Field.value.indexOf(".")==-1 || Field.value.indexOf(" ")!=-1 || Field.value.length<6) { return false; } else { return true; } } // Check if Field contains a valid date of the form dd/mm/yy function IsValidDate(Field) { if (!ContainsSomething(Field)) { Field.className='formerrors'; return false; } var indate=Field.value; var sdate = indate.split("/") var chkDate = new Date(Date.parse(indate)) var cmpDate = (chkDate.getMonth()+1)+ "/"+(chkDate.getDate())+ "/"+(chkDate.getYear()) var indate2 = (Math.abs(sdate[0]))+"/"+( Math.abs(sdate[1]))+ "/"+(Math.abs(sdate[2])) if (indate2 != cmpDate || cmpDate == "NaN/NaN/NaN") { return false } else { return true; } } // Check if Field contains numeric data only function IsNum(Field) { if (!ContainsSomething(Field)) { return false; } theNum = parseFloat(Field.value); if (Field.value != '' + theNum) { Field.className='formerrors'; return false; } Field.className='formok'; return true; } // Check if Field contains only letters function IsOnlyLetters(Field) { if (!ContainsSomething(Field)) { return false; } var Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÜÖÄ'´" for (i=0; i < Field.value.length; i++) { var CheckChar = Field.value.charAt(i); CheckChar = CheckChar.toUpperCase(); if (Letters.indexOf(CheckChar) == -1) { return false; } } return true; } // Check if Field contains only digits in range Min to Max function IsInRange(Field, Min, Max) { if (IsNum(Field) == false) { return false; } if (Field.value < Min || Max < Field.value) { return false; } return true; } //Check if Field contains required characters only var mikExp = /[%\&\_\=]/; function RequiredCharacter(Field) { if(Field.value.search(mikExp) != -1) { return false; } return true; } // Check if Field is not equal to strCompare function IsNotEqual(Field, strCompare) { if (Field.value== strCompare) { Field.className='formerrors'; return false; } Field.className='formok'; return true; } function isCreditCard(st) { if (st.length > 19) { return (false); } sum = 0; mul = 1; l = st.length; for (i = 0; i < l; i++) { digit = st.substring(l-i-1,l-i); tproduct = parseInt(digit ,10)*mul; if (tproduct >= 10) { sum += (tproduct % 10) + 1; } else { sum += tproduct; } if (mul == 1) { mul++; } else { mul--; } } if ((sum % 10) == 0) { return (true); } else { return (false); } } function IsVisa(cc) { if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4)) { return isCreditCard(cc); } cc.className='formerrors'; return false; } function IsMasterCard(cc) { firstdig = cc.substring(0,1); seconddig = cc.substring(1,2); if (((cc.length == 16) || (cc.length == 13)) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5))) { return isCreditCard(cc); } cc.className='formerrors'; return false; } function IsAmericanExpress(cc) { firstdig = cc.substring(0,1); seconddig = cc.substring(1,2); if ((cc.length == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7))) { return isCreditCard(cc); } cc.className='formerrors'; return false; } function IsDinerscc(cc){ firstdig = cc.substring(0,1); seconddig = cc.substring(1,2); if ((cc.length == 14) && (firstdig == 3) && ((seconddig == 8) || (seconddig == 0) || (seconddig == 6))) { return isCreditCard(cc); } cc.className='formerrors'; return false; } function IsValidCC(Field) { tempString = ""; bag = "- "; for (i = 0; i < Field.value.length; i++) { var c = Field.value.charAt(i); if (bag.indexOf(c) == -1) tempString += c; } cc = tempString; if (!isCreditCard(cc)) { Field.className='formerrors'; return false; } if (!IsMasterCard(cc) && !IsVisa(cc) && !IsAmericanExpress(cc) && !IsDinerscc(cc)) { Field.className='formerrors'; return false; } Field.className='formok'; return true; } ////////////////////////validate url ////////////////////////////////////// function CheckURL(Field){ if (!ContainsSomething(Field)) { Field.className='formerrors'; return false; } if((Field.value.indexOf('http://www.',0) != 0) || (Field.value.length <11) || (Field.value.indexOf('.',0) <8) || (Field.value.lastIndexOf('.')> (Field.value.length - 3)) || (Field.value.lastIndexOf('.') <(Field.value.length - 4))) { Field.className='formerrors'; return false; } else { Field.className='formok'; return true; } }