i’m using jquery validation plugin and i’attempting to define a rule for the only field of form: The value of the field must contain a string of five numbers( the field value will always contain letters ). I’ve try with the rule required( dependency-callback ) and got something like that:
rules: {
field: {
required: function(element) {
var value_field = $('#field').attr('value');
}
}
}
Now i need to search value_field for a string of five numbers.
Am i using the good rule for this case? And how to search for the needed string?
thanks
You need to add a custom method to the validator before you setup the validator with your rules:
then use the following rule :
fieldName : { required : true, FiveDigits: true }