NotRule

Validation rule used to negate another rule.

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

NewNotRule

Creates a new validation rule and sets its values

NewNotRule(rule IValidationRule) *NotRule

Methods

Validate

Validates a given value against this rule.

(c *NotRule) Validate(path string, schema ISchema, value any) []*ValidationResult

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

Examples

var schema = NewSchema()
    .WithRule(NewNotRule(
        NewValueComparisonRule("EQ", 1)
    ))
 
schema.Validate(1);          // Result: error
schema.Validate(5);          // Result: no error

See also