RegexValidator class

Validates strings against a regular expression pattern.

This validator uses regular expressions to validate string format, making it perfect for emails, URLs, phone numbers, and custom formats.

Example:

// Email validation
final emailValidator = RegexValidator(
  r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
  description: 'Must be a valid email address',
);

// Hexadecimal color code
final hexColorValidator = RegexValidator(
  r'^#[0-9A-Fa-f]{6}$',
  description: 'Must be a valid hex color code (e.g., #FF0000)',
);
Inheritance

Constructors

RegexValidator(String pattern, {bool caseSensitive = true, bool multiLine = false, String? customDescription})
Creates a regex validator with the specified pattern.
RegexValidator.fromMap(Map<String, dynamic> map)
Creates a RegexValidator from a map representation.
RegexValidator.fromRegExp(RegExp pattern, {String? customDescription})
Creates a regex validator with a pre-compiled RegExp.

Properties

customDescription String?
Custom description for this validator.
final
description String
Returns a human-readable description of the validation rules.
no setteroverride
hashCode int
The hash code for this object.
no setterinherited
pattern RegExp
The regular expression pattern to match against.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toMap() Map<String, dynamic>
Converts the validator to a map representation for serialization.
override
toString() String
A string representation of this object.
inherited
validate(String value) bool
Validates the given value according to the validator's rules.
override

Operators

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