parsley.js custom validator - not equal to

孤街浪徒 提交于 2019-12-11 08:13:11

问题


Hi I'm using parsleyjs for my form validation.

http://parsleyjs.org/documentation.html

I want a custom validator so that an input value can not equal what I specify...

An example using jQuery validation can be seen here... How to add a Not Equal To rule in jQuery.validation

I'm thinking something like..

$( '#form' ).parsley( {
    validators: {
      notEqual: function ( val, ??? ) {
        return val != ??? ;
      }
    }
  , messages: {
      notEqual: "Please enter a valid value"
    }
} );

Thanks


回答1:


This worked for me. You also have to set data-notEqual="#element".

validators: {
    notEqual: function ( val, elem ) {
        return val !== $( elem ).val();
    }
},
messages: {
    notEqual: "This value should not be the same."
},

Hope this is what you are looking for!



来源:https://stackoverflow.com/questions/19361050/parsley-js-custom-validator-not-equal-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!