var ErrorValue = "Error have occured:\t\n\t\n"; function IsNumeric(strString) /*check for valid numeric strings */ { var strValidChars = "0123456789."; var strChar; var blnResult = true; if (strString.length == 0) return false; /*test strString consists of valid characters listed above*/ for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult; } /*accepts the date in the format of yyyy-mm-dd*/ /* function isdate(strDate) { var dPart = eval("strDate.split('-')"); //Ensure that there are 3 values year, month, day passed to the function if(dPart.length >3){return false; } //Ensure that year, month, day passed is numeric if (!IsNumeric(dPart[0])){return false;}//year if (!IsNumeric(dPart[1])){return false;}//month if (!IsNumeric(dPart[2])){return false;}//day // if (dPart[0] < 1970){return false;} if (dPart[1] > 12){return false;} if (dPart[2] > 31){return false;} return true; }*/ function isdate(strDate) { var dPart = eval("strDate.split('/')"); //Ensure that there are 3 values month, day, year passed to the function if(dPart.length >3){return false;} //Ensure that month, day, year passed is numeric if (!IsNumeric(dPart[0])){return false;}//month if (!IsNumeric(dPart[1])){return false;}//day if (!IsNumeric(dPart[2])){return false;}//year // if (dPart[0] > 12){return false;} if (dPart[1] > 31){return false;} if (dPart[2] < 1970){return false;} return true; } function isAmericanDate(strDate) { var dPart = eval("strDate.split('/')"); //Ensure that there are 3 values month, day, year passed to the function if(dPart.length >3){return false;} //Ensure that month, day, year passed is numeric if (!IsNumeric(dPart[0])){return false;}//month if (!IsNumeric(dPart[1])){return false;}//day if (!IsNumeric(dPart[2])){return false;}//year // if (dPart[0] > 12){return false;} if (dPart[1] > 31){return false;} if (dPart[2] < 1970){return false;} return true; } function isAmericanDateGT(strDate) { var dPart = eval("strDate.split('/')"); //Ensure that there are 3 values month, day, year passed to the function if(dPart.length >3){return false;} //Ensure that month, day, year passed is numeric if (!IsNumeric(dPart[0])){return false;}//month if (!IsNumeric(dPart[1])){return false;}//day if (!IsNumeric(dPart[2])){return false;}//year // var myDate=new Date(); myDate.setFullYear(dPart[2],dPart[0]-1,dPart[1]); var today = new Date(); if (myDate>=today) { return true; } else { return false; } } function isAmericanDateLT(strDate) { var dPart = eval("strDate.split('/')"); //Ensure that there are 3 values month, day, year passed to the function if(dPart.length >3){return false;} //Ensure that month, day, year passed is numeric if (!IsNumeric(dPart[0])){return false;}//month if (!IsNumeric(dPart[1])){return false;}//day if (!IsNumeric(dPart[2])){return false;}//year // var myDate=new Date(); myDate.setFullYear(dPart[2],dPart[0]-1,dPart[1]); var today = new Date(); if (myDate<=today) { return true; } else { return false; } } /* //this format should be used in forms to validate form data. function validateFormData() { var istrue = true; if (!validateFormFields(FieldValue, FieldNameText, Type, LLength, Spaces)){istrue = false;} if (!validateFormFields(FieldValue, FieldNameText, Type, LLength, Spaces)){istrue = false;} if (!validateFormFields(FieldValue, FieldNameText, Type, LLength, Spaces)){istrue = false;} if (!validateFormFields(FieldValue, FieldNameText, Type, LLength, Spaces)){istrue = false;} alert(ErrorValue); return istrue; } */ function validateFormFields(FieldValue, FieldNameText, Type, LLength, Spaces) { //declare variable var FieldLength = 0; FieldLength = FieldValue.length; // if (Spaces == false) { if (FieldValue == "") { ErrorValue = ErrorValue +"* "+ FieldNameText+" has to be passed.\t\n"; return false; } } //if length was not passed then do not validate the length if (LLength != "") { if (FieldLength > LLength) { //error handle if FieldValue length is greater than the specified max length if (FieldNameText.length > LLength) { ErrorValue = ErrorValue +"* "+ FieldNameText+" max length is "+LLength+"\t\n"; return false; } } } if (Type=="DATE") { if (!isdate(FieldValue)) { ErrorValue = ErrorValue + "* " + FieldNameText + " expects a valid date in the format [DD/MM/YYYY]. \t\n"; return false; } } if (Type=="AMERICANDATE") { if (!isAmericanDate(FieldValue)) { ErrorValue = ErrorValue + "* " + FieldNameText + " expects a valid date in the format [MM/DD/YYYY]. \t\n"; return false; } } if (Type=="AMERICANDATEGT") { if (!isAmericanDateGT(FieldValue)) { ErrorValue = ErrorValue + "* " + FieldNameText + " expects a valid date greater than or equal the current date. \t\n"; return false; } } if (Type=="AMERICANDATELT") { if (!isAmericanDateLT(FieldValue)) { ErrorValue = ErrorValue + "* " + FieldNameText + " expects a valid date less than or equal the current date. \t\n"; return false; } } if ((Type == "NUMERIC") || (Type=="FLOAT")) { if (!IsNumeric(FieldValue)) { ErrorValue = ErrorValue + "* "+FieldNameText + " expects a valid number. \t\n"; return false; } } return true; } function isValidWebSite(Str) { var x = Str; var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (filter.test(x)) return true; else return false; } function isAlphaNumeric(Str) { var strEntered = Str; var alphanumericRegex = /^[a-zA-Z0-9]+$/; if (alphanumericRegex.test(strEntered)) return true; else return false; } /*--TRIM FUNCTION--*/ function Trim(TRIM_VALUE) { if( TRIM_VALUE.length < 1 ){ return""; } TRIM_VALUE = RTrim(TRIM_VALUE); TRIM_VALUE = LTrim(TRIM_VALUE); if( TRIM_VALUE=="" ) { return ""; } else { return TRIM_VALUE; } } //End Function function RTrim(VALUE) { var w_space = String.fromCharCode(32); var v_length = VALUE.length; var strTemp = ""; if(v_length < 0){ return""; } var iTemp = v_length -1; while(iTemp > -1) { if(VALUE.charAt(iTemp) == w_space) { } else { strTemp = VALUE.substring(0,iTemp +1); break; } iTemp = iTemp-1; } //End While return strTemp; } //End Function function LTrim(VALUE) { var w_space = String.fromCharCode(32); if(v_length < 1){return"";} var v_length = VALUE.length; var strTemp = ""; var iTemp = 0; while(iTemp < v_length) { if(VALUE.charAt(iTemp) == w_space){ } else { strTemp = VALUE.substring(iTemp,v_length); break; } iTemp = iTemp + 1; } //End While return strTemp; } //End Function