jQuery.validator.addMethod("ValiPass", function(value, element,params) {
var exp = new RegExp(params);//实例化正则对象,参数为传入的正则表达式
return exp.test(value); //测试是否匹配
}, "密码必须包含数字、字母大、小写、符号四种");
然后表单验证中
rules: {
newPassword: {
minlength: 8,
maxlength: 12,
ValiPass: "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$"
}
},
messages: {
newPassword:{
minlength: "密码长度不能小于8个字母",
ValiPass:"密码必须包含数字、字母大、小写、符号四种"
},
},
原文地址:https://www.cnblogs.com/yang-mountain/p/9952996.html
时间: 2024-10-12 02:30:56