jQuery Validate: Validate that one field, or both fields of a pair are required
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a form that I am trying to validate that has two fields:
Here's my jQuery Validation wireup:
What I'd like to do is add an additional validation rule that says: the form is not valid if both fieldEmailAddress and fieldMobileNumber are blank. In other words, I'd like to make it such that at least one of either fieldEmailAddress or fieldMobileNumber is required. It seems like most of the jQuery Validation custom methods are designed to only work for one field at a time - I need to validate both.
require_from_group: [x, '.class'] // x = number of items required from a group of items. // .class = class assigned to every form element included in the group.