JQuery validation rule depends on another rule -


i have form required field depend on form field value. required rule may true or false depend on other field. issue accept rule should there if required true. how can that?

..., fielda: {      maxlength: 3,      accept: "[0-9]{3}",      required: function() {           if($('#fieldb').val() == 'abcd') {                return false;           } else {                return true;           }      } },... 

thanks in advance.

i didn't realize 'accept' rule custom rule. edited code check whether optional field. this.optional(element)

jquery.validator.addmethod("accept", function(value, element, param) {     return this.optional(element) || value.match(new regexp("^" + param + "$")); }); 

@barmar help.


Comments

Popular posts from this blog

python - Setting ctypes.Structure default values -

javascript - Hide toolbar of pdf file opened inside iframe using firefox -

Ansible - ERROR! the field 'hosts' is required but was not set -