jquery add method and implementation

醉酒当歌 提交于 2019-12-07 19:41:55

问题


Ok so from my previous post I got a lot of good feedback. I am starting this one so that I can start a new question and add the full code I have. i know something is messing up, but here is my method and implementation.

jquery.validator.addMethod("passwordRules", function(input) {
    var reg = /^{^%\s]{6,}$/;
    var reg2 = /[a-zA-Z]/;
    var reg3 = /[0-9]/;
    return reg.test(input) && reg2.test(input) && reg3.test(input);
});

that is my add method. here is how I am trying to apply it to the new password field. My question here is do i use required? I am lost.

$("<%= NewPass1.GetName() %>").validate({
    rules:{
        required: { passwordRules: true }
}, messages: {
    "<%= NewPass1.GetName() %>": {
required: WrapError("Invalid", "The password contains invalid....")}
  }
});

I just need to reassure that the password box only allows min of 6 chars, no spaces or %, at least one number and at least one letter.


回答1:


If you define a new method, you simply have to use the method name as a key in the rules set like this:

$("<%= NewPass1.GetName() %>").validate({
    rules:{
        passwordRules: true
    }
});

d.



来源:https://stackoverflow.com/questions/3094733/jquery-add-method-and-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!