Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery validation of a form name with square brackets

I have the following validation code for a text field but the 'field' below needs to be replaced with the name of the text field, which is created dynamically.

My problem is it has a square bracket in the name - options[483998]

How would I go about adding this to the code below as obviously if I do a direct replace of field with options[483998] it creates invalid coding.

jQuery("#product_addtocart_form").validate({
  rules: {
    field: {
      required: true,
      range: [100, 2540]
    }
  }
});
like image 754
Vince P Avatar asked Nov 03 '11 09:11

Vince P


2 Answers

Demo - http://jsfiddle.net/sY82j/

jQuery("#product_addtocart_form").validate({
  rules: {
    "options[483998]": {
      required: true,
      range: [100, 2540]
    }
  }
});
like image 58
Jayendra Avatar answered Nov 15 '22 21:11

Jayendra


Just put it in quotes: "options[483998]"

like image 26
Ariel Avatar answered Nov 15 '22 21:11

Ariel