How to customize error message using jQuery.validator placeholders? -


i'm trying add custom form validators. , i'm stuck message customizing issue.

let's want check if field value not exceeds max allowed value. know 'validation plugin' has "max" validator - sample:

$.validator.addmethod("max-numeric", function(value, element, param) {     var maxvalue = $(element).attr("data-max");     return (!maxvalue) || maxvalue >= value; }, $.validator.format('applicants must older {0} , younger {1} years of age'));  $("#data-form").validate({     rules: {         "form.params1.p4":         {             "min-numeric": [5, 6]         }     } }); 

i cannot comprehend responsible replacing {0} , {1} in '$.validator.format'. , how pass parameters?

update:

here message get:

applicants must older true , younger [object htmlinputelement] years of age

i cannot comprehend responsible replacing {0} , {1} in '$.validator.format'. , how pass parameters?

in example above, {0} represents first parameter , {1} represents second parameter. parameters [5, 6] respectively , automatic replacement of such within message handled automatically plugin.

so when writing custom method, there nothing special you'll need do. if pass 3 parameters method...

custommethod: [34, 50, 10] 

...then you'll have {0}, {1}, , {2} available custom message, representing each value of parameters respectively.

it works.


if there going wrong, it's not obvious op aside from:

the method called max-numeric, you're referencing min-numeric in rules object of .validate() method.

as long have 2 parameters next max-numeric, example work.

max-numeric: [5, 6] 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -