layui.use("form", function () { var form = layui.form; //自定义验证规则 form.verify({ minsize: ["{name}最少 {0} 个字符"], maxsize: ["{name}最多 {0} 个字符"], min: ["{name}必须大于等于 {0}"], max: ["{name}必须小于等于 {0}"], equals: ["两次输入不一致"], gtnumber: ["最大值必须大于等于最小值"], gtdate: ["结束时间必须大于等于开始时间"], required: [ "[\\s]+", "{name}不能为空" ], telephone: [ "^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$", "请输入有效的{name},如:010-29292929" ], mobilephone: [ "^[1][0-9]{10}$", "请输入有效的{name}" ], muchtel: [ "^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?|[1][0-9]{10}$", "请输入有效的{name}" ], email: [ "^[a-za-z0-9_\.\-]+\@([a-za-z0-9\-]+\.)+[a-za-z0-9]{2,4}$", "请输入有效的{name}" ], date: [ "^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$", "请输入有效的{name},如:2008-08-08" ], datetime: [ "^((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29))\\s+([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$", "请输入有效的{name},如:2008-08-08 08:08:08" ], ip: [ "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", "请输入有效的{name}" ], chinese: [ "^[\u4e00-\u9fa5]+$", "{name}请输入中文" ], url: [ "^http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?$", "请输入有效的{name}" ], urlnohttp: [ "^([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?$", "请输入有效的{name}" ], zipcode: [ "^[1-9]\\d{5}$", "请输入有效的{name}" ], qq: [ "^[1-9]\\d{4,10}$", "请输入有效的{name}" ], onlynumber: [ "^[-]?[0-9]+$", "{name}请输入数字" ], onlynumberwide: [ "^[-]?\\d+(\\.\\d{1,4})?$", "{name}请输入整数或小数" ], onlydecimal: [ "^[-]?\\d+(\\.\\d{1,2})$", "{name}请输入2位以内的小数" ], illegalletter: [ "^[^\`\{\}\[!\(\+~@#%\^&\*\)\|\\\\:;\'\"><\?/=_]+$", "{name}含有非法字符,请检查" ], onlyletter: [ "^[a-za-z]+$", "{name}请输入英文字母" ], nospecialcaracters: [ "^[a-za-z][0-9a-za-z_]+$", "{name}格式错误,可使用字母、数字及下划线,需以字母开头" ], username: [ "^[a-za-z][0-9a-za-z_]{3,15}$", "{name}格式错误,4~16个字符,可使用字母、数字及下划线,需以字母开头" ], password: [ "^(?![a-za-z]+$)(?![a-z\\w]+$)(?![a-z\\w]+$)(?![0-9\\w]+$)[a-za-z0-9\\w]{8,16}$", "{name}格式错误,8-16个字符,需包含字母、数字、特殊符号中的任意两项" ], ajaxmember: ["/youhoo/home/ajaxmember", "{name}已存在"], ajaxmember2: ["/youhoo/home/ajaxmember2", "{name}不存在"] }); }); //验证身份证号 function checkidcard(elem) { if (elem.val() == "") return; //这个可以验证15位和18位的身份证,并且包含生日和校验位的验证。 //如果有兴趣,还可以加上身份证所在地的验证,就是前6位有些数字合法有些数字不合法。 var num = elem.val().touppercase(); //身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符x。 if (!(/(^\d{15}$)|(^\d{17}([0-9]|x)$)/.test(num))) { return "请输入有效的身份证号码"; } //校验位按照iso 7064:1983.mod 11-2的规定生成,x可以认为是数字10。 //下面分别分析出生日期和校验位 var len, re; len = num.length; if (len == 15) { re = new regexp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/); var arrsplit = num.match(re); //检查生日日期是否正确 var dtmbirth = new date('19' + arrsplit[2] + '/' + arrsplit[3] + '/' + arrsplit[4]); var bgoodday; bgoodday = (dtmbirth.getyear() == number(arrsplit[2])) && ((dtmbirth.getmonth() + 1) == number(arrsplit[3])) && (dtmbirth.getdate() == number(arrsplit[4])); if (!bgoodday) { return "请输入有效的身份证号码"; } else { //将15位身份证转成18位 //校验位按照iso 7064:1983.mod 11-2的规定生成,x可以认为是数字10。 var arrint = new array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); var arrch = new array('1', '0', 'x', '9', '8', '7', '6', '5', '4', '3', '2'); var ntemp = 0, i; num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6); for (i = 0; i < 17; i++) { ntemp += num.substr(i, 1) * arrint[i]; } num += arrch[ntemp % 11]; } } if (len == 18) { re = new regexp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|x)$/); var arrsplit = num.match(re); //检查生日日期是否正确 var dtmbirth = new date(arrsplit[2] + "/" + arrsplit[3] + "/" + arrsplit[4]); var bgoodday; bgoodday = (dtmbirth.getfullyear() == number(arrsplit[2])) && ((dtmbirth.getmonth() + 1) == number(arrsplit[3])) && (dtmbirth.getdate() == number(arrsplit[4])); if (!bgoodday) { return "请输入有效的身份证号码"; } else { //检验18位身份证的校验码是否正确。 //校验位按照iso 7064:1983.mod 11-2的规定生成,x可以认为是数字10。 var valnum; var arrint = new array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); var arrch = new array('1', '0', 'x', '9', '8', '7', '6', '5', '4', '3', '2'); var ntemp = 0, i; for (i = 0; i < 17; i++) { ntemp += num.substr(i, 1) * arrint[i]; } valnum = arrch[ntemp % 11]; if (valnum != num.substr(17, 1)) { return "请输入有效的身份证号码"; } } } return ""; } $(function () { //设置默认提示 $(".search input, .tablelayout input, .tablelayout textarea").each(function () { if ($(this).attr("type") == "submit" || $(this).attr("type") == "reset" || $(this).attr("type") == "button") return; if ($(this).attr("placeholder") == undefined && !$(this).hasclass("input_60")) $(this).attr("placeholder", "请输入" + $(this).parent().prev().text().replace(/:/g, "")); }) //图标悬浮提示 $(document).on("mouseenter", ".icontips", function () { var title = $(this).attr("data-title"); if (!title || title == "null" || title == "") title = "暂无提示信息!"; layer.tips("
" + title + "", this, { time: -1 }); }).on("mouseleave", ".icontips", function () { $(".layui-layer-tips").remove(); }) })