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, String? data})
Create a new form validator with message and data
FormValidator.custom(bool customRule(dynamic data)?, {String? message})
Create a new custom validation rule
FormValidator.email({String? message})
Validate an email message The message to display if the email 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.rule(dynamic rules, {String? message, String? data})
Create a new form validator with rules

Properties

customRule bool Function(dynamic data)?
getter/setter pair
data String?
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) → dynamic
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