如何使用jQuery验证插件有条件地更改minlength

时间:2011-09-16 10:24:33

标签: javascript jquery jquery-validate

我正在使用jQuery验证插件。

我想动态选择minlength。

目前我正在尝试这样的事情,但它没有用。

minlength:function () {
    if(val == 1 ) {
        return 3;
    }
    else{
         return 1;
    }
},

我想根据条件设置minlength 1或3。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

假设范围内有val,你必须执行函数来实际设置值,试试这个......

minlength:(function () {
    if(val == 1 ) {
        return 3;
    }
    else{
         return 1;
    }
})(),

在Kanishka Panamaldeniya的澄清之后更新:

您必须使用addMethod()添加自己的自定义验证器方法。请参阅here for further reference and examples

相关问题