Reputation: 1113
I have an element like
<input type="text" id="no_of_days" name="admin_setting[no_of_days]" class="txtbox" maxlength="50" />
when I validate like,
jQuery("form").validate({
rules :{
admin_setting[no_of_days] : "required"
},
messages :{
admin_setting[no_of_days] : "Please enter the No of Days"
}
});
It throws the error. Please provide me the way to add the rules inside the validate() function for the element which has the name in array form like "admin_setting[no_of_days]".
I don't want to use .rules() function, as more number of fields to be added in validate() function, instead of calling rules() function for every element.
Upvotes: 0
Views: 489
Reputation: 40582
You need to quote the key, as it's a non-standard key name (i.e. it contains [...]):
jQuery("form").validate({
rules :{
'admin_setting[no_of_days]' : "required"
},
messages :{
'admin_setting[no_of_days]' : "Please enter the No of Days"
}
});
Upvotes: 1