ExcludedRule

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

Implements: IValidationRule

Description

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

Constructors

Creates a new validation rule and sets its values

ExcludedRule(List<dynamic>? values)

  • values: List<dynamic>? - list of constants with value must be excluded from

Instance 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.

@override

void validate(String? path, Schema schema, dynamic value, List<ValidationRule> results)

  • path: String? - dot notation path to the value that is to be validated.
  • schema: Schema - (not used in this implementation).
  • value: dynamic - value that is to be validated.
  • results: List<ValidationRule> - results of the validation.

Examples

var schema =  Schema()
    .withRule( ExcludedRule(1, 2, 3));

schema.validate(2);      // Result: 2 must not be one of 1, 2, 3
schema.validate(10);     // Result: no errors

See also