Validation rule that allows you to check combinations of rules created with AND logical operations.

Inherits: IValidationRule


The AndRule class allows you to validate combinations of rules created with AND logical operations.

Important points

  • When one or more of the combined rules return errors, then this rule returns all the errors that appeared.
  • When none of the combined rules returns errors, then this rule also returns no errors.


Creates a new validation rule and sets its values.

public AndRule(params IValidationRule[] rules)

Instance methods


Validates a given value against this rule.

public void Validate(string path, Schema schema, object value, List<ValidationResult> results)

  • path: string - a dot notation path to the value.
  • schema: Schema - a schema this rule is called from
  • value: object - a value to be validated.
  • results: List<ValidationResult> - a list with validation results to add new results.


var schema = new Schema().WithRule(new AndRule(
    new ValueComparisonRule("GTE", 1),
    new ValueComparisonRule("LTE", 10)

schema.Validate(0);          // Result: 0 must be greater or equal to 1
schema.Validate(5);          // Result: no error
schema.Validate(20);         // Result: 20 must be letter or equal 10

See also