我很困惑,因为
可能是:((((
我什至尝试使用其他IDE,因为我认为它有问题。除了拼写错误和被忘记的链接js文件之外,自定义验证器不起作用还有哪些可能性?我已经尝试过正则表达式功能正常工作
jQuery.validator.addMethod("forpassword",
function(value, element){
var regex = /([A-Za-z\d]*[A-Z]+[A-Za-z\d]*[\d]+[A-Za-z\d]*)|([A-Za-z\d]*[\d]+[A-Za-z\d]*[A-Z]+[A-Za-z\d]*)/;
return this.optional(element) || regex.test(value);
},
"Our custom password checker"
);
jQuery.validator.addMethod("foremail",
function (value, element) {
var regex = /^.+@cmyemail.on.com$/;
return this.optional(element) || regex.test(value);
},
"Our custom email checker"
);
function myformvalidate()
{
var form = $("#myform");
form.validate({
rules:{
txtEmail:{
required: true,
email: true,
foremail: true
},
txtPassword:{
required: true,
minlength: 8,
forpassword: true
}
},
messages:{
txtEmail:{
required: "You must enter Email address",
email: "Please enter a valid email",
foremail: "You must enter a conestoga email"
},
txtPassword:{
required: "Password is required",
minlength:"Password must be at least 8 characters long",
forpassword: "Password must contain at least 1 cap 1 digit"
}
}
});
return form.valid();
}
//the html code
<label for="Password">Password:</label>
<input type="password" id="txtPassword" name="txtPassword">
<label for="Email">Email:</label>
<input type="text" name="txtEmail" id="txtEmail">
答案 0 :(得分:0)
我弄清楚了,原因确实很有趣...(?)我将验证JS库文件链接到具有自定义验证..的js文件下面,这导致了错误。我不知道您如何在html文档中链接js文件:0