parsley.js custom validator - not equal to

2019-07-25 13:48发布

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条回答
时光不老,我们不散
2楼-- · 2019-07-25 14:11

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!

查看更多
登录 后发表回答