【问题标题】:To check string in jquery.validate在 jquery.validate 中检查字符串
【发布时间】:2010-12-14 12:26:20
【问题描述】:

对于密码验证,我使用equalTo:"#password" 是否可以通过在 jquery.validate 中提供 equalTo:"string to check" 来检查一些刺痛

【问题讨论】:

    标签: jquery jquery-validate


    【解决方案1】:

    equalTo 在这里只需要一个选择器,但您可以将a custom method 用于您想要的检查:

    jQuery.validator.addMethod("equals", function(value, element, param) { 
      return this.optional(element) || value === param; 
    }, jQuery.format("You must enter {0}"));
    

    那么就可以使用同名规则了:

    equals:"string to check"
    

    You can test it here.

    【讨论】:

    • 我需要使用 notequalto 但在 jquery.validate 中没有选项
    • @Mohan - 你可以创建一个类似的方法,notequals,只需将value === param 更改为value != param
    【解决方案2】:

    用下面的函数覆盖equalTo:

    equalTo: function(element) {                    
                            if( ( 
                                    $("#password").val() == "Your String Value Here"
                                ) {
    return true;
    }else{
    return false;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-15
      • 1970-01-01
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      相关资源
      最近更新 更多