/******************************* ** 表单验证 使用说明: 在使用表单的页面填入如下script 注意:checkNumber(),checkLength()等方法并不检查是否为空
...
********************************/ ////////////////////////////////////////////////////////////////////////////// ///////////////系统常用javascriptfunction///////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //传附件调用文件 //参数据:fname:显示名称的名称,fid:显示名称代码的名称 function fileselect(fname,fid) { var return_value=showModalDialog("../public/upload/file.php?names="+fname.value+"&ids="+fid.value+"","","dialogWidth:37;dialogHeight:12;dialogTop:250;dialogLeft:230;status:no;scrollbars:no;help:no"); if((typeof(return_value)=="undefined")) return; else var str1=""; var str2=""; tmpstr=return_value.split("*"); str1=tmpstr[0]; str2=tmpstr[1]; fname.value=str1; fid.value=str2; } //选择用户或部门: //参数据:SHOWName:显示名称的名称,SHOWID:显示名称代码的名称,allids表示传来的ID function userselect(SHOWName,SHOWID,allids){ // if (allids!="") //allids=","+allids+","; //allids=allids+","; var selectData=window.showModalDialog("../public/select/model.php?check=change&userid="+allids,"","dialogWidth:28;dialogHeight:19;dialogTop:150;dialogLeft:380;status:no;scrollbars:no;help:no") if((typeof(selectData)=="undefined")) return; else var selectName=""; var selectID=""; tmpstr=selectData.split("*"); tmpstr0=tmpstr[0]; selectName=tmpstr0.split(","); tmpstr1=tmpstr[1]; selectID=tmpstr1.split(","); if (selectName==""){ // alert("提示!选择为空,请重选!"); SHOWName.value=" "; SHOWID.value=" "; } else{ SHOWName.value=selectName; SHOWID.value=selectID; } } //选择用户组: //参数据:SHOWName:显示名称的名称,SHOWID:显示名称代码的名称,allids表示传来的ID function groupselect(SHOWName,SHOWID,allids){ // allids=","+allids+","; var selectData=window.showModalDialog("../public/select/selectgroup.jsp?&allids="+allids+"","","dialogWidth:27;dialogHeight:17;dialogTop:200;dialogLeft:280;status:no;scrollbars:no;help:no") var selectName=""; var selectID=""; tmpstr=selectData.split("*"); tmpstr0=tmpstr[0]; selectName=tmpstr0.split(","); tmpstr1=tmpstr[1]; selectID=tmpstr1.split(","); if (selectName==""){ alert("提示!选择为空,请重选!"); SHOWName.value=" "; SHOWID.value=" "; } else{ SHOWName.value=selectName; SHOWID.value=selectID; } } //////////////////////////////////////////////////////////////////////////// // 是否为空,非空返回真,不非为空返回假 function isBlank(str) { var blankFlag = true; if (str.length == 0) return true; for (var i = 0; i < str.length; i++) { if ((str.charAt(i) != "") && (str.charAt(i) != " ")) { blankFlag = false; break; } } return blankFlag; } function checkNotNull(theField, fieldName) { if(isBlank(theField.value)){ alert(fieldName + "不可为空!"); theField.focus(); return false; } return true; } // 是否为数字 function checkNumber(theField, fieldName) { var pattern = /^([0-9]|(-[0-9]))[0-9]*((\.[0-9]+)|([0-9]*))$/; if(theField.value == "") return true; if (!pattern.test(theField.value)) { alert(fieldName + "必须为合法数字"); theField.focus(); theField.select(); return false; } return true; } // 是否为指定范围数字 function checkNumberRange(theField, fieldName, min, max) { if(theField.value == "") return true; if (!checkNumber(theField, fieldName)) return false; if ((min != "") && (theField.value < min)) { alert(fieldName + "不可小于" + min + "!"); theField.focus(); theField.select(); return false; } if ((max != "") && (theField.value > max)) { alert(fieldName + "不可超过" + max + "!"); theField.focus(); theField.select(); return false; } return true; } // 是否为整数 function checkInteger(theField, fieldName) { var pattern = /^(\d|(-\d))\d*$/; if(theField.value == "") return true; if (!pattern.test(theField.value)) { alert(fieldName + "必须为整数!"); theField.focus(); theField.select(); return false; } return true; } // 是否为指定范围内整数 function checkIntegerRange(theField, fieldName, min, max) { if(theField.value == "") return true; if (!checkInteger(theField, fieldName)) return false; if ((min != "") && (theField.value < min)) { alert(fieldName + "不可小于" + min + "!"); theField.focus(); theField.select(); return false; } if ((max != "") && (theField.value > max)) { alert(fieldName + "不可超过" + max + "!"); theField.focus(); theField.select(); return false; } return true; } // 是否为正数 function checkPositiveNumber(theField, fieldName) { if(theField.value == "") return true; if (theField.value.charAt(0) == '-') { alert(fieldName + "必须为正数!"); theField.focus(); return false; } return true; } // 限制字串最大长度 function checkLength(theField, fieldName, maxLength) { if(theField.value == "") return true; if (theField.value.length > maxLength) { alert(fieldName + "的字数最多为" + maxLength + "字!"); theField.select(); theField.focus(); return false; } return true; } // 限制字串长度,注意参数顺序 function checkLength2(theField, fieldName, maxLength, minLength) { if(theField.value == "") return true; if (theField.value.length > maxLength) { alert(fieldName + "的字数最多为" + maxLength + "字!"); theField.focus(); return false; } if ((minLength != "") && (theField.value.length < minLength)) { alert(fieldName + "的字数最少为" + minLength + "字!"); theField.focus(); return false; } return true; } // 所输入字符串是否均为合法字符 // charBag中为包含所有合法字符的字符串 function checkStrLegal(theField, fieldName, charBag) { if(theField.value == "") return true; for (var i = 0; i < theField.value.length; i++) { var c = theField.value.charAt(i); if (charBag.indexOf(c) == -1) { alert(fieldName + "含有非法字符(" + c + ")!"); theField.focus(); return false; } } return true; } // 所输入字符串是否均为合法字符 // charBag中为包含非法字符的字符串 function checkStrLegal2(theField, fieldName, charBag) { if(theField.value == "") return true; for (var i = 0; i < theField.value.length; i++) { var c = theField.value.charAt(i); if (charBag.indexOf(c) > -1) { alert(fieldName + "含有非法字符(" + c +")!"); theField.focus(); return false; } } return true; } // 电子邮件验证 function checkEmail(theField) { var pattern = /^.+@.+\..+$/; if(theField.value == "") return true; if (!pattern.test(theField.value)) { alert("请输入合法的电子邮件地址"); theField.focus(); theField.select(); return false; } return true; } // 是否为只读域(如file,text等域只接受右边按钮选择传回的结果) function checkReadField() { alert("请点击后面的图标进行选择"); // this.blur(); }