Validator class
A utility class that provides common form field validators.
All validators return null if the input is valid, otherwise return a string error message.
Constructors
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
-
alphabetic(
String? value, {String fieldName = 'This field'}) → String? - Validates that the input contains only alphabetic characters.
-
alphanumeric(
String? value, {String fieldName = 'This field'}) → String? - Validates that the input contains only alphanumeric characters.
-
creditCard(
String? value) → String? - Validates a credit card number using Luhn algorithm.
-
date(
String? value, {String format = 'yyyy-MM-dd'}) → String? - Validates a date string in various formats.
-
email(
String? value) → String? - Validates if the input is a valid email address.
-
match(
String? value, String? otherValue, {String fieldName = 'Fields'}) → String? - Validates that two fields are equal (e.g., password and confirm password).
-
maxLength(
String? value, int length, {String fieldName = 'This field'}) → String? - Validates that the input does not exceed a maximum length.
-
minLength(
String? value, int length, {String fieldName = 'This field'}) → String? - Validates that the input meets a minimum length.
-
noProfanity(
String? value, {List< String> blockedWords = const []}) → String? - Validates that the input doesn't contain profanity or restricted words.
-
number(
String? value, {double? min, double? max}) → String? - Validates that the input is a number.
-
password(
String? value, {int minLength = 8, bool requireSpecialChar = true, bool requireUppercase = true, bool requireLowercase = true, bool requireNumber = true}) → String? - Validates a strong password with optional rules.
-
phone(
String? value, {int min = 8, int max = 15}) → String? - Validates that the input is a valid phone number.
-
postalCode(
String? value, {String country = 'US'}) → String? - Validates a postal/zip code.
-
range(
String? value, {required num min, required num max, String fieldName = 'Value'}) → String? - Validates that the input is within a specific range.
-
required(
String? value, {String fieldName = 'This field'}) → String? - Validates that the field is not empty.
-
url(
String? value, {bool requireHttps = false}) → String? - Validates that the input is a valid URL.
-
username(
String? value, {int minLength = 3, int maxLength = 20}) → String? - Validates that the input is a valid username.