Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Validation plugin custom method. Multiple parameters

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" }             }         }); }); 
like image 996
BuzzBubba Avatar asked Sep 02 '09 10:09

BuzzBubba


1 Answers

Javascript arrays:

[value1,value2,value3] 

SO your code might be:

inputEl: { required: true, math: [2, 3 ,4 , 5] } 
like image 160
jantimon Avatar answered Sep 23 '22 00:09

jantimon