0

in my page there are few hidden field which are filled with the correct value from a script. These fields are validated server side against code injection and others malicius attacks but I'd like to put some code to validate the fields also client-side. My aim is to request that field with name = "name1" and "name2" contain a string of two (not more not less) letters (not numbers) to submit the form. My problem is that for the others fields I am using jQuery Validation Plugin 1.9.0 but if the field is hidden the script doesn't work on it. I'm using the following code to tell validation which roles to follow:

$(document).ready(function(){ $("#myform").validate({ rules:{ my_hidden_field:{ required: true, minlength: 2, } }, messages:{ my_hidden_field: "this field is not valid" }, errorLabelContainer: "#BoxValidator", wrapper: "li", }); }); 
2
  • Please ask one question at a time. Perhaps "How to validate hidden fields with jQuery Validation Plugin?" and "How to run verify into doesn't contain numbers...?" e.g. Commented Jun 26, 2012 at 20:30
  • I've deleted the second part of the question, keeping the most important and the most related with the title. Commented Jun 26, 2012 at 20:34

1 Answer 1

3

Use ignore: [] to validate hidden fields:

$("#myform").validate({ rules:{ my_hidden_field:{ required: true, minlength: 2, } }, messages:{ my_hidden_field: "this field is not valid" }, errorLabelContainer: "#BoxValidator", wrapper: "li", ignore: [] // <---- }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.