I have a form that needs to be validated but it does not have a submit button. So to get the validation done, I followed the example on http://docs.jquery.com/Plugins/Validation/valid
which tells to call .valid() function. So i added the following code which worked fine:
$(".getcars").click(function() {
valid = $("#form1").valid();
if(valid){
ajaxCall();
}
});
Now I want to add more rules to the validation field , so i tried
jQuery.validator.addMethod("lettersandnumonly", function(value, element) {
return this.optional(element) || /^[0-9A-Za-z]+$/i.test(value);
}, "Letters and numbers only ");
jQuery.validator.addMethod("nowhitespace", function(value, element) {
return this.optional(element) || /^\S+$/i.test(value);
}, "No white space please");
$(".getcars").click(function() {
valid = $("#form1").valid(
{
rules: {
postal_code: {
maxlength: 6,
lettersandnumonly: true,
nowhitespace: true
}
}
});
if(valid){
ajaxCall();
}
});
but this is not working. Can anyone tell me what I am doing wrong while adding the rule?