jquery添加方法和实现 [英] jquery add method and implementation

查看:184
本文介绍了jquery添加方法和实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,从我以前的文章中,我得到了很多好的反馈。我开始写这篇文章,以便我可以开始一个新的问题并添加完整的代码。

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....")}
  }
});

我只需要确认密码框只允许最少6个字符,不能包含空格或%至少有一个数字和至少一个字母。

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.

推荐答案

如果您定义了一个新方法,您只需使用方法名称作为这样的规则中的关键:

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。

这篇关于jquery添加方法和实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆