layui常用的验证
var LayVerifyExtend = {
notnullNonnegativeInteger: function (value, item) { //value:表单的值、item:表单的DOM对象
if (!/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\d+)?$/.test(value))
return '只能输入非负整数!';
},
maxlength: function (value, item) { //value:表单的值、item:表单的DOM对象
if (GetLength(value) > item.maxLength)
return '只能输入' + item.maxLength + '个字符!';
},
PHONE: function (value, item) { //value:表单的值、item:表单的DOM对象 (验证手机号非必填)
if (value.length > 0 && value != "" && !(/^1[3456789]\d{9}$/.test(value)))
return '手机号格式错误!';
},
IdCard: function (value, item) {//验证身份证号是否正确
//var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
//if (reg.test(value) === false) {
// return '身份证格式错误!';
//}
var val = value;
if (val == '') {
//身份证号不能为空
//return '身份证号不能为空!';
}
else {
if (val.length==18 && val.substr(val.length - 1, val.length) == "x") {
val = val.substring(0, 17) + "X";
$(item).val(val.substring(0, 17) + "X");
}
if (!CheckIdCard(val)) {
return '身份证格式错误!';
}
}
},
faxandphone: function (value, item) {//固话与手机验证,非必填
var reg = /^((0\d{2,3}-\d{7,8})|(1[357894]\d{9}))$/;
if (value.length > 0 && reg.test(value) === false) {
return '电话格式错误!';
}
},
PositiveInteger: function (value, item) { //非空的正整数
debugger;
var reg = /^[+]{0,1}(\d+)$/
if (value.length > 0 && reg.test(value) === false)
return '只能输入正整数!';
},
morezero: function (value, item) {//大于等于0
if (!/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/.test(value))
return '只能输入大于等于0的数!';
},
nullormorezero: function (value, item) {//大于等于0
if (value != '') {
if (!/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/.test(value))
return '只能输入大于等于0的数!';
}
}
}
//加载公共验证方法库
form.verify(LayVerifyExtend);