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 message and data
FormValidator.boolean({String? message})
Validate a value is a boolean message The message to display if the value is invalid
FormValidator.capitalized({String? message})
Validate that the value is capitalized message The message to display if the value is invalid
FormValidator.contains(List<String> values, {String? message})
Validate the value contains one of the values message The 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 message The message to display if the value is invalid
FormValidator.dateAgeIsOlder(int age, {String? message})
Validate that the date is older than age message The message to display if the value is invalid age The age to compare
FormValidator.dateAgeIsYounger(int age, {String? message})
Validate that the date is younger than age message The message to display if the value is invalid age The age to compare
FormValidator.dateInFuture({String? message})
Validate that the date is in the future message The message to display if the value is invalid
FormValidator.dateInPast({String? message})
Validate that the date is in the past message The message to display if the value is invalid
FormValidator.email({String? message})
Validate an email message The message to display if the email is invalid
FormValidator.isFalse({String? message})
Validate that the value is false message The message to display if the value is invalid
FormValidator.isTrue({String? message})
Validate that the value is true message The message to display if the value is invalid
FormValidator.lowercase({String? message})
Validate that the value is lowercase message The message to display if the value is invalid
FormValidator.maxLength(int value, {String? message})
Validate that the value is a maximum of value characters message The message to display if the value is invalid value The maximum number of characters
FormValidator.maxSize(int value, {String? message})
Validate that the value is a maximum size of value message The message to display if the value is invalid value The maximum size
FormValidator.maxValue(int value, {String? message})
Validate that the value is a maximum of value message The message to display if the value is invalid value The maximum value
FormValidator.minLength(int value, {String? message})
Validate that the value is a minimum of value characters message The message to display if the value is invalid value The minimum number of characters
FormValidator.minSize(int value, {String? message})
Validate that the value is a minimum size of value message The message to display if the value is invalid value The minimum size
FormValidator.minValue(int value, {String? message})
Validate that the value is a minimum of value message The message to display if the value is invalid value The minimum value
FormValidator.notEmpty({String? message})
Validate that the value is not empty message The message to display if the value is invalid
FormValidator.numeric({String? message})
Validate that the value is numeric message The 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 strength 1: 1 uppercased letter, 1 digit, 8 characters strength 2: 1 uppercased letter, 1 digit, 1 special character, 8 characters message The message to display if the password is invalid
FormValidator.phoneNumber({String? message})
Validate a UK phone number message The message to display if the phone number is invalid
FormValidator.phoneNumberUs({String? message})
Validate a US phone number message The message to display if the phone number is invalid
FormValidator.postcodeUk({String? message})
Validate that the value is a valid postcode for the UK message The message to display if the value is invalid
FormValidator.regex(String regex, {String? message})
Validate that the value matches a regex pattern message The 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 message The message to display if the value is invalid
FormValidator.url({String? message})
Validate a URL message The message to display if the URL is invalid
FormValidator.zipcodeUs({String? message})
Validate that the value is a valid zipcode for the US message The 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 value characters
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 value characters
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 regex pattern
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