How to add a Not Equal To rule in jQuery.validation

前端 未结 9 967
小鲜肉
小鲜肉 2020-11-28 03:23

I was wondering how to make it so that I could make a rule where a field is not equal to a value. Like I have a field called \'name\' so I don\'t want \'name\' = \'Your Name

9条回答
  •  余生分开走
    2020-11-28 03:58

    Thanks for @Nick Craver♦'s answer, but in my working environment, it needs to be slightly modified before it could work.

     $.validator.addMethod("notEqualTo", function(value, element, param) {
           return this.optional(element) || value != $(param).val();
     }, 'This two elements are the same, please change it.');
    

提交回复
热议问题