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.
base64({bool urlSafe = false, String errorMessage = 'Please enter a valid Base64 encoded string'}) String? Function(String?)
Ensures the string is Base64 encoded.
boolean({String errorMessage = 'Please enter true or false'}) String? Function(String?)
Ensures the string represents a boolean value.
byteLength(int min, {int? max, String errorMessage = 'Length is out of range'}) String? Function(String?)
Ensures the string's UTF-8 byte length falls within a range.
contains(String seed, {bool ignoreCase = false, int minOccurrences = 1, String errorMessage = 'Required text is missing'}) String? Function(String?)
Ensures the string contains the seed substring.
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.
decimal({String errorMessage = 'Please enter a valid decimal number'}) String? Function(String?)
Ensures the string represents a decimal number.
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.
float({double? min, double? max, String errorMessage = 'Please enter a valid number'}) String? Function(String?)
Ensures the string is a finite floating-point number.
fqdn({String errorMessage = 'Please enter a valid domain name'}) String? Function(String?)
Ensures the string is a fully qualified domain name.
hexadecimal({String errorMessage = 'Please enter a valid hexadecimal number'}) String? Function(String?)
Ensures the string is a hexadecimal number.
hexColor({String errorMessage = 'Please enter a valid hex color (e.g. #ff0000)'}) String? Function(String?)
Ensures the string is a valid hex color.
inList(Iterable<String> allowed, {String errorMessage = 'Value is not allowed'}) String? Function(String?)
Ensures the string is one of the allowed values.
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.
jwt({String errorMessage = 'Please enter a valid JWT'}) String? Function(String?)
Ensures the string is a valid JSON Web Token.
latLong({String errorMessage = 'Please enter valid coordinates'}) String? Function(String?)
Ensures the string is a valid latitude,longitude pair.
length(int min, {int? max, String errorMessage = 'Length is out of range'}) String? Function(String?)
Ensures the string length falls within the specified range.
lowercase({String errorMessage = 'Must be lowercase'}) String? Function(String?)
Ensures the string is entirely lowercase.
macAddress({String errorMessage = 'Please enter a valid MAC address'}) String? Function(String?)
Ensures the string is a valid MAC address.
matches(Pattern pattern, {String errorMessage = 'Invalid format'}) String? Function(String?)
Ensures the string matches the given pattern.
md5({String errorMessage = 'Please enter a valid MD5 hash'}) String? Function(String?)
Ensures the string is a valid MD5 hash.
mongoId({String errorMessage = 'Please enter a valid MongoDB ObjectId'}) String? Function(String?)
Ensures the string is a valid MongoDB ObjectId.
numeric({String errorMessage = 'Please enter a valid number'}) String? Function(String?)
Ensures the string is a valid number.
octal({String errorMessage = 'Please enter a valid octal number'}) String? Function(String?)
Ensures the string is an octal number.
phone({String errorMessage = 'Please enter a valid phone number'}) String? Function(String?)
Ensures the string is a valid phone number.
port({String errorMessage = 'Please enter a valid port number'}) String? Function(String?)
Ensures the string is a valid port number.
required({String errorMessage = 'This field is required'}) String? Function(String?)
Ensures the field is not null or empty.
semVer({String errorMessage = 'Please enter a valid semantic version'}) String? Function(String?)
Ensures the string is a valid Semantic Version.
slug({String errorMessage = 'Please enter a valid slug'}) String? Function(String?)
Ensures the string is a valid URL slug.
strongPassword({int minLength = 8, int minLowercase = 1, int minUppercase = 1, int minNumbers = 1, int minSymbols = 1, String errorMessage = 'Password is not strong enough'}) String? Function(String?)
Ensures the string is a strong password.
uppercase({String errorMessage = 'Must be uppercase'}) String? Function(String?)
Ensures the string is entirely uppercase.
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.