PatternValidator class

A validator that checks if the value matches pattern.

The PatternValidator can be used with FieldControllers holding values of type String. It ensures that the value matches pattern.

If the value is null it is treated as valid by default.

Properties

  • pattern: The pattern that the field should match.
  • message: An optional custom error message to display when invalid.

Example

FieldController<String> field = FieldController(
  key: 'string',
  validators:[PatternValidator(RegExp(r'^[a-z]+$'))],
);

// If field.value = 'Hello123!', validation fails.
// If field.value = 'hello', validation passes.

See also

Inheritance

Constructors

PatternValidator.new(RegExp pattern, {String? message})

Properties

hashCode int
The hash code for this object.
no setterinherited
message String?
finalinherited
pattern RegExp
The pattern that the field should match.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(FieldController<String> controller) ValidationResult
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onValidate(FieldController<String> controller) ValidationResult
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited