You cannot find documentation, because you cannot do this.
Using the jQuery Validation plugin and custom method, you cannot declare a built-in validAge rule when you need to pass parameters.
<input type="text" name="dob" id="dob" validAge="[17,66]" />
Only certain rules that can be declared with a boolean value (can be declared as class names), or rules that are also HTML5 validation attributes, can be declared inline.
For your custom method with parameters, it should (maybe) be declared in the .validate() method ...
$('#myform').validate({
EDIT :
As @John Bubriski notes, this should work. The operator incorrectly accessed parameters in its user method.
The OP used JSON.parse ...
var range = JSON.parse(params);
which throws a syntax error in the console because it does not recognize params as a valid JSON string. Analysis of the params variable is not required.
Parameters are passed to the function as params , so they can be accessed directly as params[0] , params[1] , etc.
jQuery.validator.addMethod('validAge', function (value, element, params) { value = eLifeViewModel.age(); if (value === '') { // <- You do NOT need this! /* Use the "required" rule instead of this conditional */ return false; } return value > params[0] && value < params[1]; }, $.format('Applicants must be older than {0} and younger than {1} years of age'));
source share