jQuery ValidationEngine: How to validate that at least one of a set of fields is not empty?

Dmitriy Sosunov picture Dmitriy Sosunov · Feb 11, 2011 · Viewed 22.2k times · Source

In our project we are using ValidationEngine, and we don't have the ability to replace it with another plug-in.

Our form has ten inputs and some of them are optional, but at least one of the optional fields must be included.

So, how do you validate inputs in this case?

Sample:

form
  input1
  input2
  intpu3

input1: required

At least one of input2 and input3 must be present -- if both are empty validation should fail.

Answer

Terrance picture Terrance · Jun 8, 2011

The validation engine now supports group Validation.Go to jQuery form validation plugin @ github and ake a look at groupRequired. The syntax looks something like this.

<input value="" class="validate[groupRequired[payments]]" type="text" name="creditcard" id="creditcard" />
<input class="validate[groupRequired[payments]]" type="text" id="paypal" name="paypal"/>