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);