记录几个常用的前台数据库的校验
/*字符串去空格*/function trimStrOT(str){ return str==null||str==''?'':str.replace(/\s+/g,'');}/*字符串类型验证*/function strTypeJdg(str,jdgType){ if (trimStrOT(str)!=''){ var jdgStr=''; switch(jdgType){ case null: jdgStr='required';/*非空*/ break; case 'digital':/*数字*/ jdgStr=/^[0-9]+([.]\d{1,4})?$/; break; case 'pInteger':/*非0正整数*/ jdgStr=/^\+?[1-9][0-9]*$/; break; case 'money':/*金钱*/ jdgStr=/^[0-9]*(\.[0-9]{1,7})?$/; break; case 'username':/*数字、26个英文字母或者下划线组成*/ jdgStr=/[\u4E00-\u9FA5\w]{2,}$/; break; case 'password':/*密码组成判断,字母开头,长度在6~20之间,只能包含字符、数字和下划线*/ jdgStr=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){5,19}$/; break; case 'chn':/*汉字*/ jdgStr=/^[\u4e00-\u9fa5]{0,}$/; break; case 'tel':/*座机、传真号码*/ jdgStr=/^[0-9]{3,4}(\-)[0-9]{7,8}(\-[0-9]{1,4})?$/; break; case 'mobile':/*手机号码*/ jdgStr=/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/; break; case 'mail':/*邮箱*/ jdgStr=/^[a-zA-Z0-9_\-]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/; break; case 'postal':/*邮政编码*/ jdgStr=/^[0-9]{6}$/; break; case 'date':/*中文日期*/ jdgStr=/^(\d{4})-(0\d{1}|1[0-2])-(0\d{1}|[12]\d{1}|3[01])$/; break; case 'ID':/*身份证*/ jdgStr=/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; break; default: break; } return jdgStr!=''?jdgStr!='required'?jdgStr.test(str):trimStrOT(str)!='':false; }else{ return false; }}/*对比前后两个值*/function compareValJdg(beforeID, afterID){ var beforeObj = $("#" + beforeID); var afterObj = $("#" + afterID); var beforeVal = trimStrOT(beforeObj.val()); var afterVal = trimStrOT(afterObj.val()); if(beforeVal == afterVal){ beforeObj.hide(); }else{ beforeObj.show(); }}/* * 重复密码验证 * pwdID:密码控件id * rePwdID:重复密码控件id * tipsText:提示文本 * required:是否必填项 * */function passwordJdg(pwdID,rePwdID,tipsText,required) { var passwordObj = $("#" + pwdID); var rePasswordObj = $("#" + rePwdID); var password=trimStrOT(passwordObj.val()); var rePassword=trimStrOT(rePasswordObj.val()); var validateResult=false; if(password!=''&&rePassword!=''){ validateResult=password===rePassword; tipsEleOperation(rePasswordObj,tipsText,validateResult); }else{ validateResult=required?false:true; } return validateResult;}/**2个日期前后验证* startID:开始日期控件id* endID:结束日期控件id* tipsText:提示文本* required:是否必填项* */function doubleDateJdg(startID, endID, tipsText,required) { var startDateObj = $("#" + startID); var endDateObj = $("#" + endID); var startDate=trimStrOT(startDateObj.val()); var endDate=trimStrOT(endDateObj.val()); var validateResult=false; if(startDate!=''&&endDate!=''){ var d1 = new Date(startDate.replace(/\-/g, "\/")); var d2 = new Date(endDate.replace(/\-/g, "\/")); validateResult=startDate!=''&&endDate!=''&&d1