ExcludedRule

Validation rule to check that one or more values are excluded from the list of constants.

Description

The ExcludedRule allows you to verify that none of the values specified in the rule is present in a list of constants.

Constructors

NewExcludedRule

Creates a new validation rule and sets its values

NewExcludedRule(values …any) *ExcludedRule

  • values: …any - list of values that must be excluded from a list of constants

Methods

Validate

Validates the given value. None of the values set in this ExcludedRule object must exist in the value that is given for validation to pass.

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

  • path: string - dot notation path to the value that is to be validated.
  • schema: ISchema - (not used in this implementation).
  • value: any - value that is to be validated.
  • results: []*ValidationResult - results of the validation.

Examples

schema := NewSchema()
	.WithRule(NewExcludedRule(1, 2, 3));
    
schema.Validate(2);      // Result: 2 must not be one of 1, 2, 3
schema.Validate(10);     // Result: no errors 

See also