To check string in jquery.validate

前端 未结 2 1383
名媛妹妹
名媛妹妹 2020-12-18 13:41

for password validation i am using equalTo:\"#password\" Whether it is possible to check some sting by giving as equalTo:\"string to check\" in jqu

相关标签:
2条回答
  • 2020-12-18 14:20

    equalTo only takes a selector here, but you can make a custom method for the check you want:

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

    Then you can use the a rule with the same name:

    equals:"string to check"
    

    You can test it here.

    0 讨论(0)
  • 2020-12-18 14:23

    Override the equalTo: with below function

    equalTo: function(element) {                    
                            if( ( 
                                    $("#password").val() == "Your String Value Here"
                                ) {
    return true;
    }else{
    return false;
    }
    
    0 讨论(0)
提交回复
热议问题