function FormChecker_isString(arg){ var reg=/^(\ *)$/; return !reg.test(arg); } function FormChecker_lessThan( arg, len ){ if( arg.length > parseInt(len) ){ return false; } return true; } function FormChecker_isInt(arg,min,max){ var reg=/^(\+|\-)?(0|([1-9]\d*))$/; if ( min==null && max==null){ return reg.test(arg); } if ( min!=null && max!=null){ return reg.test(arg) && arg >= min && arg<= max ; } if ( min!=null && max==null){ return reg.test(arg) && arg >= min ; } if ( min==null && max!=null){ return reg.test(arg) && arg<= max ; } } function FormChecker_isPInt(arg,min,max){ var reg=/^\+?[1-9]\d*$/; if ( min==null && max==null){ return reg.test(arg); } if ( min!=null && max!=null){ return reg.test(arg) && arg >= min && arg<= max ; } if ( min!=null && max==null){ return reg.test(arg) && arg >= min ; } if ( min==null && max!=null){ return reg.test(arg) && arg<= max ; } } function FormChecker_isPercent(arg){ var reg=/^(([1-9]\d?)|100|0)$/; return reg.test(arg); } function FormChecker_isFloat(arg, min, max){ var reg=/^(\+|\-)?(\d+|\b)?(\.\d+)?((\e|\E)?(\+|\-)?\d+)?$/; if ( min==null && max==null){ return reg.test(arg); } if ( min!=null && max!=null){ return reg.test(arg) && arg >= min && arg<= max ; } if ( min!=null && max==null){ return reg.test(arg) && arg >= min ; } if ( min==null && max!=null){ return reg.test(arg) && arg<= max ; } } function FormChecker_isPFloat(arg,min,max){ var reg=/^\+?(\d+|\b)?(\.\d+)?((\e|\E)?(\+|\-)?\d+)?$/; if ( min==null && max==null){ return reg.test(arg); } if ( min!=null && max!=null){ return reg.test(arg) && arg >= min && arg<= max ; } if ( min!=null && max==null){ return reg.test(arg) && arg >= min ; } if ( min==null && max!=null){ return reg.test(arg) && arg<= max ; } } function FormChecker_isEMail(arg){ var reg=/^(\w|\.|-)+\@(\w|\.|-)+\.+(\w)+$/i; return reg.test(arg); } function FormChecker_isURL(arg){ var reg=/^[a-z]+\:\/\/(\w|\w(\w|\.|\-)*\w)(\:\d{1,5})?((\/|\?).*)?$/i; return reg.test(arg); } function FormChecker_isID(arg){ var reg=/^([a-z]|\_)\w*$/i; return reg.test(arg); } function FormChecker_isDate(arg){ var reg=/^\d{4}\/(1[012]|0?[1-9]){2}\/([12]\d|3[01]|0?[1-9]){2}$/; if(reg.test(arg)){ var nreg=/[1-9]\d*/; var numbers=arg.split("\/"); var year=parseInt(numbers[0].substring(numbers[0].search(nreg),numbers[0].length)); var month=parseInt(numbers[1].substring(numbers[1].search(nreg),numbers[1].length)); var day=parseInt(numbers[2].substring(numbers[2].search(nreg),numbers[2].length)); var thisDay=new Date(year,month-1,day); //alert(year+" "+month+" "+day+"\n"+thisDay.getFullYear()+" "+(thisDay.getMonth()+1)+" "+thisDay.getDate()); return (year==thisDay.getFullYear()&&month==(thisDay.getMonth()+1)&&day==thisDay.getDate()); } else{ return false; } } function FormChecker_isHrisDate(arg){ var reg=/^\d{4}\/(1[012]|0?[1-9]){2}\/([12]\d|3[01]|0?[1-9]){2}$/; if(reg.test(arg)){ var nreg=/[1-9]\d*/; var numbers=arg.split("\/"); var year=parseInt(numbers[0].substring(numbers[0].search(nreg),numbers[0].length)); var month=parseInt(numbers[1].substring(numbers[1].search(nreg),numbers[1].length)); var day=parseInt(numbers[2].substring(numbers[2].search(nreg),numbers[2].length)); var thisDay=new Date(year,month-1,day); //alert(year+" "+month+" "+day+"\n"+thisDay.getFullYear()+" "+(thisDay.getMonth()+1)+" "+thisDay.getDate()); return (year==thisDay.getFullYear()&&month==(thisDay.getMonth()+1)&&day==thisDay.getDate()); } else{ return false; } } function FormChecker_isTime(arg){ var reg=/^([01]?\d|2[0-3]|)\:[0-5]?\d:[0-5]?\d$/; return reg.test(arg); } function FormChecker_addType(typeName,typeFunc,errorMes){ this.testType[typeName]=typeFunc; var errorMessage=errorMes; if(errorMes==null) errorMessage="should be a valid "+typeName.toUpperCase(); this.typeError[typeName]=errorMessage; } function FormChecker_addField(fieldName,typeName,errorMes){ this.fieldType[fieldName]=typeName; var errorMessage=errorMes; if(errorMes==null) errorMessage=fieldName.toUpperCase()+" "+this.typeError[typeName]+"!"; this.fieldError[fieldName]=errorMessage; } function FormChecker_checkAll(){ var ret=true; var mes=""; for(fieldName in this.fieldType){ var typeName=this.fieldType[fieldName]; var func=this.testType[typeName]; var testValue=eval("document."+this.formName+"."+fieldName).value; if(testValue==null||testValue==""){ ret=false; mes+="\n"+fieldName.toUpperCase()+" can't be blank!"; } else{ if(!func(testValue)){ ret=false; mes+="\n"+this.fieldError[fieldName]; } } } if(!ret) alert(mes); return ret; } function FormChecker_checkField(fld,typeName,min,max,errorMes){ var errorMessage=errorMes; if(errorMes==null || errorMes==""){ errorMessage="This Field "+this.typeError[typeName]; } var func=this.testType[typeName]; if(func(fld.value,min,max)){ return true; } else{ alert(errorMessage); return false; } } function FormChecker_checkFieldLessThan(fld,grid,errorMes){ var errorMessage=errorMes; if(errorMes==null){ errorMessage="This Field shouldn't be longer than "+grid; } if( fld.value.length > parseInt(grid) ){ alert(errorMessage); fld.value=''; return false; } return true; } function FormChecker(formName){ this.testType=new Array(); this.typeError=new Array(); this.fieldType=new Array(); this.fieldError=new Array(); this.isString=FormChecker_isString; this.testType["string"]=this.isString; this.typeError["string"]="can't be made up by only blankspace"; this.lessThan=FormChecker_lessThan; this.testType["lessThan"]=this.lessThan; this.typeError["lessThan"]="string to long"; this.isInt=FormChecker_isInt; this.testType["int"]=this.isInt; this.typeError["int"]="should be a valid Integer"; this.isPercent=FormChecker_isPercent; this.testType["percent"]=this.isPercent; this.typeError["percent"]="should be a valid Integer between 0 and 100"; this.isFloat=FormChecker_isFloat; this.testType["float"]=this.isFloat; this.typeError["float"]="should be a valid Float"; this.isPInt=FormChecker_isPInt; this.testType["pInt"]=this.isPInt; this.typeError["pInt"]="should be a valid Integer greater than 0"; this.isPFloat=FormChecker_isPFloat; this.testType["pFloat"]=this.isPFloat; this.typeError["pFloat"]="should be a valid Float greater than 0"; this.isEMail=FormChecker_isEMail; this.testType["email"]=this.isEMail; this.typeError["email"]="should be a valid EMail expression like john.smith_us@hotmail.com"; this.isURL=FormChecker_isURL; this.testType["url"]=this.isURL; this.typeError["url"]="should be a URL with protocol like http://www.google.com/search?p=wahaha"; this.isID=FormChecker_isID; this.testType["id"]=this.isID; this.typeError["id"]="can just contains 'a'-'z','_','0'-'9', and it can't be started with '0'-'9'"; this.isDate=FormChecker_isDate; this.testType["date"]=this.isDate; this.typeError["date"]="should be a YYYY/MM/DD valid date expression"; this.isHrisDate=FormChecker_isHrisDate; this.testType["hrisdate"]=this.isHrisDate; this.typeError["hrisdate"]="should be a DD/MM/YYYY valid date expression"; this.isTime=FormChecker_isTime; this.testType["time"]=this.isTime; this.typeError["time"]="should be an HH:MM:SS valid time expression"; this.addType=FormChecker_addType; this.addField=FormChecker_addField; this.checkAll=FormChecker_checkAll; this.checkField=FormChecker_checkField; this.checkFieldLessThan=FormChecker_checkFieldLessThan; this.formName=formName; } function alertDel(){ return confirm("Do you sure DELETE?"); }