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

NotRule(rule: IValidationRule)

Instance methods

validate

Validates a given value against this rule.

validate(path: str, schema: Schema, value: Any, results: List[ValidationResult])

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

Examples

schema = Schema().with_rule(NotRule(ValueComparisonRule("EQ", 1)))
schema.validate(1)          # Result: error
schema.validate(5)          # Result: no error

See also