Validator class

A utility class for Flutter Form validation. Provides methods that return a validator function suitable for TextFormField.

Example:

TextFormField(
  validator: Validator.email(errorMessage: 'Please enter a valid email'),
)

Constructors

Validator()

Properties

hashCode int
The hash code for this object.
no setterinherited
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

Operators

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

Static Methods

alpha({String errorMessage = 'Only letters are allowed'}) String? Function(String?)
Ensures the string consists only of letters.
alphanumeric({String errorMessage = 'Only letters and numbers are allowed'}) String? Function(String?)
Ensures the string consists only of letters and numbers.
ascii({String errorMessage = 'Only ASCII characters are allowed'}) String? Function(String?)
Ensures the string only contains ASCII characters.
base32({String errorMessage = 'Please enter a valid Base32 encoded string'}) String? Function(String?)
Ensures the string is a valid Base32 encoded string.
base58({String errorMessage = 'Please enter a valid Base58 encoded string'}) String? Function(String?)
Ensures the string is a valid Base58 encoded string.
boolean({String errorMessage = 'Please enter true or false'}) String? Function(String?)
Ensures the string represents a boolean value.
creditCard({String errorMessage = 'Please enter a valid credit card number'}) String? Function(String?)
Ensures the string is a valid credit card.
date({String errorMessage = 'Please enter a valid date'}) String? Function(String?)
Ensures the string is a valid date.
email({String errorMessage = 'Please enter a valid email address'}) String? Function(String?)
Ensures the string is a valid email.
equals(String comparison, {String errorMessage = 'Values do not match'}) String? Function(String?)
Ensures the string matches the comparison string exactly.
hexColor({String errorMessage = 'Please enter a valid hex color (e.g. #ff0000)'}) String? Function(String?)
Ensures the string is a valid hex color.
integer({String errorMessage = 'Please enter a valid whole number'}) String? Function(String?)
Ensures the string is a valid integer.
ip({int? version, String errorMessage = 'Please enter a valid IP address'}) String? Function(String?)
Ensures the string is a valid IP address.
json({String errorMessage = 'Please enter valid JSON'}) String? Function(String?)
Ensures the string is valid JSON.
length(int min, {int? max, String errorMessage = 'Length is out of range'}) String? Function(String?)
Ensures the string length falls within the specified range.
numeric({String errorMessage = 'Please enter a valid number'}) String? Function(String?)
Ensures the string is a valid number.
phone({String errorMessage = 'Please enter a valid phone number'}) String? Function(String?)
Ensures the string is a valid phone number.
required({String errorMessage = 'This field is required'}) String? Function(String?)
Ensures the field is not null or empty.
url({String errorMessage = 'Please enter a valid URL'}) String? Function(String?)
Ensures the string is a valid URL.
uuid({String errorMessage = 'Please enter a valid UUID'}) String? Function(String?)
Ensures the string is a valid UUID.