NotRule

Validation rule used to negate another rule.

Implements: IValidationRule

Description

The NotRule class allows you to negate a rule. Thus, when the embedded rule returns errors, then the negated rule returns no errors and vice versa.

Constructors

Creates a new validation rule and sets its values

public constructor(rule: IValidationRule)

Instance methods

validate

Validates a given value against this rule.

public validate(path: string, schema: Schema, value: any, results: ValidationResult[]): void

  • path: string - dot notation path to the value.
  • schema: Schema - schema this rule is called from
  • value: any - value to be validated.
  • results: ValidationResult[] - list with validation results to add new results.

Examples

let schema = new Schema()
    .withRule(new NotRule(
        new ValueComparisonRule("EQ", 1)
    ));
    
schema.validate(1);          // Result: error
schema.validate(5);          // Result: no error

See also