I’m trying to use a custom validator with jQuery Validation plugin.
However, I’m unsure how are you supposed to pass multiple arguments to a validation method?
I’ve tried using (2,3), curly braces and combinations, but I have failed.
This is the code – ???? marks the area I need info about:
$(document).ready(function() {
jQuery.validator.addMethod("math", function(value, element, params) {
return this.optional(element) || value == params[0] + params[1];
}, jQuery.format("Please enter the correct value for {0} + {1}"));
$("#form_register").validate({
debug: true,
rules: {
inputEl: { required: true, math: ???? }
},
messages: {
inputEl: { required: "Required", math: "Incorrect result" }
}
});
});
Javascript arrays:
SO your code might be: