I have two fields (mobile and telephone) which are both being validated by the Validation plugin for jquery although Im struggling to get it working..
One of the fields must be populated although Im failing to successfully validation that checks on of the fields and it that has a value to allow t开发者_如何学Pythonhe other field to pass validation, even though its empty.
Is there an easy way to do this? I've tried add my own rules but I cant get it working :(
many thanks
required
can take a callback function to determine if the validation should apply, so something like this should work:
$("#myform").validate({
rules: {
attr1: {
required: function(el) {
return $("#attr2").val();
}
},
attr2: {
required: function(el) {
return $("#attr1").val();
}
}
}
});
Tweaking the functions as necessary.
Edit: relevant docs link http://docs.jquery.com/Plugins/Validation/Methods/required#dependency-expression
精彩评论