FormValidator class
FormValidator is a class that helps in managing form validation It is used in the NyFormData class Example:
class RegisterForm extends NyFormData {
@override
Map<String, dynamic> validate() => {
"Email": FormValidator.rule("email", message: "Invalid email")
};
Constructors
- FormValidator({String? message, dynamic data})
-
Create a new form validator with
messageanddata - FormValidator.boolean({String? message})
-
Validate a value is a boolean
messageThe message to display if the value is invalid - FormValidator.capitalized({String? message})
-
Validate that the value is capitalized
messageThe message to display if the value is invalid -
FormValidator.contains(List<
String> values, {String? message}) -
Validate the value contains one of the
valuesmessageThe message to display if the value is invalid - FormValidator.custom(bool customRule(dynamic data)?, {String? message})
- Create a new custom validation rule
- FormValidator.date({String? message})
-
Validate that the value is a date
messageThe message to display if the value is invalid - FormValidator.dateAgeIsOlder(int age, {String? message})
-
Validate that the date is older than
agemessageThe message to display if the value is invalidageThe age to compare - FormValidator.dateAgeIsYounger(int age, {String? message})
-
Validate that the date is younger than
agemessageThe message to display if the value is invalidageThe age to compare - FormValidator.dateInFuture({String? message})
-
Validate that the date is in the future
messageThe message to display if the value is invalid - FormValidator.dateInPast({String? message})
-
Validate that the date is in the past
messageThe message to display if the value is invalid - FormValidator.email({String? message})
-
Validate an email
messageThe message to display if the email is invalid - FormValidator.isFalse({String? message})
-
Validate that the value is false
messageThe message to display if the value is invalid - FormValidator.isTrue({String? message})
-
Validate that the value is true
messageThe message to display if the value is invalid - FormValidator.lowercase({String? message})
-
Validate that the value is lowercase
messageThe message to display if the value is invalid - FormValidator.maxLength(int value, {String? message})
-
Validate that the value is a maximum of
valuecharactersmessageThe message to display if the value is invalidvalueThe maximum number of characters - FormValidator.maxSize(int value, {String? message})
-
Validate that the value is a maximum size of
valuemessageThe message to display if the value is invalidvalueThe maximum size - FormValidator.maxValue(int value, {String? message})
-
Validate that the value is a maximum of
valuemessageThe message to display if the value is invalidvalueThe maximum value - FormValidator.minLength(int value, {String? message})
-
Validate that the value is a minimum of
valuecharactersmessageThe message to display if the value is invalidvalueThe minimum number of characters - FormValidator.minSize(int value, {String? message})
-
Validate that the value is a minimum size of
valuemessageThe message to display if the value is invalidvalueThe minimum size - FormValidator.minValue(int value, {String? message})
-
Validate that the value is a minimum of
valuemessageThe message to display if the value is invalidvalueThe minimum value - FormValidator.notEmpty({String? message})
-
Validate that the value is not empty
messageThe message to display if the value is invalid - FormValidator.numeric({String? message})
-
Validate that the value is numeric
messageThe message to display if the value is invalid - FormValidator.password({int strength = 1, String? message})
-
Validate a password with a strength of 1 or 2
strength1: 1 uppercased letter, 1 digit, 8 charactersstrength2: 1 uppercased letter, 1 digit, 1 special character, 8 charactersmessageThe message to display if the password is invalid - FormValidator.phoneNumber({String? message})
-
Validate a UK phone number
messageThe message to display if the phone number is invalid - FormValidator.phoneNumberUs({String? message})
-
Validate a US phone number
messageThe message to display if the phone number is invalid - FormValidator.postcodeUk({String? message})
-
Validate that the value is a valid postcode for the UK
messageThe message to display if the value is invalid - FormValidator.regex(String regex, {String? message})
-
Validate that the value matches a
regexpatternmessageThe message to display if the value is invalid - FormValidator.rule(dynamic rules, {String? message, dynamic data})
-
Create a new form validator with
rules - FormValidator.uppercase({String? message})
-
Validate that the value is uppercase
messageThe message to display if the value is invalid - FormValidator.url({String? message})
-
Validate a URL
messageThe message to display if the URL is invalid - FormValidator.zipcodeUs({String? message})
-
Validate that the value is a valid zipcode for the US
messageThe message to display if the value is invalid
Properties
- customRule ↔ bool Function(dynamic data)?
-
getter/setter pair
- data ↔ dynamic
-
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- message ↔ String?
-
getter/setter pair
- rules ↔ dynamic
-
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
boolean(
) → FormValidator - Validate a value is a boolean
-
capitalized(
) → FormValidator - Validate that the value is capitalized
-
contains(
List< String> values) → FormValidator -
Validate the value contains one of the
values -
date(
) → FormValidator - Validate that the value is a date
-
dateAgeIsOlder(
int age) → FormValidator -
Validate that the date is older than
age -
dateAgeIsYounger(
int age) → FormValidator -
Validate that the date is younger than
age -
dateInFuture(
) → FormValidator - Validate that the date is in the future
-
dateInPast(
) → FormValidator - Validate that the date is in the past
-
email(
) → FormValidator - Validate an email
-
isFalse(
) → FormValidator - Validate that the value is false
-
isTrue(
) → FormValidator - Validate that the value is true
-
lowercase(
) → FormValidator - Validate that the value is lowercase
-
maxLength(
int value) → FormValidator -
Validate that the value is a maximum of
valuecharacters -
maxSize(
int value) → FormValidator -
Validate that the value is a maximum size of
value -
maxValue(
int value) → FormValidator -
Validate that the value is a maximum of
value -
minLength(
int value) → FormValidator -
Validate that the value is a minimum of
valuecharacters -
minSize(
int value) → FormValidator -
Validate that the value is a minimum size of
value -
minValue(
int value) → FormValidator -
Validate that the value is a minimum of
value -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notEmpty(
) → FormValidator - Validate that the value is not empty
-
numeric(
) → FormValidator - Validate that the value is numeric
-
password(
{required int strength}) → FormValidator - Validate that the value is a password
-
phoneNumberUk(
) → FormValidator - Validate a UK phone number
-
phoneNumberUs(
) → FormValidator - Validate a US phone number
-
postcodeUk(
) → FormValidator - Validate that the value is a valid postcode for the UK
-
regex(
String regex) → FormValidator -
Validate that the value matches a
regexpattern -
setData(
dynamic data) → void - Set the data for the form validator
-
toString(
) → String -
A string representation of this object.
inherited
-
toValidationRule(
) → List - Transform the FormValidator into a validation rule
-
uppercase(
) → FormValidator - Validate that the value is uppercase
-
url(
) → FormValidator - Validate a URL
-
zipcodeUs(
) → FormValidator - Validate that the value is a valid zipcode for the US
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited