EmailValidator class

A validator that checks whether a given string is a valid email address.

The EmailValidator ensures that the input follows the basic structure of an email address, including a local part, the @ symbol, and a domain.

Email validation rules:

  • The email must contain exactly one @ symbol.
  • The local part can include letters, numbers, and special characters.
  • The domain must contain at least one dot (.).
  • Consecutive dots (..) are not allowed.

Example

final validator = EmailValidator(message: 'Invalid email');

print(validator.validate('user@example.com'));  // null (valid)
print(validator.validate('user@sub.domain.com'));  // null (valid)
print(validator.validate('invalid-email'));  // 'Invalid email' (invalid)
print(validator.validate('user@domain'));  // 'Invalid email' (invalid)
print(validator.validate('user@domain..com'));  // 'Invalid email' (invalid)
Inheritance

Constructors

EmailValidator.new({required String message})
Creates an EmailValidator with a custom error message.

Properties

hashCode int
The hash code for this object.
no setterinherited
message String
The error message to be returned when validation fails.
finalinherited
pattern String
The regex pattern used for validation.
finalinherited
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
toString() String
A string representation of this object.
inherited
validate(covariant String value) String?
Validates the provided value.
inherited

Operators

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