StringMust class
A Validator that validates a String field. It provides numerous constraints that can be imposed on the String field.
Constraints can be chained together via the cascade operator ...
Constraints that come first take precedence.
Example:
Former(
form: ...
schema: MySchema(
someStringField: StringMust()..hasMinLength(10)..beAnEmail(),
)
)
In the above snippet, the StringMust validator ensures that
someStringField is a string that has at least 10 characters and is an email.
Constructors
Properties
Methods
-
beAnEmail(
[String? errorMessage]) → void - Instructs StringMust to make sure the given string is a valid email. Note that this is just a simple regex check from ihateregex.io that should cover most use cases. The backend should be responsible for anything more complicated.
-
exist(
[String? errorMessage]) → void - Instructs StringMust to make sure the given string is not null.
-
hasMaxLength(
int len, [String? errorMessage]) → void -
Instructs StringMust to make sure the given string
is at most
lencharacters long. -
hasMinLength(
int len, [String? errorMessage]) → void -
Instructs StringMust to make sure the given string
is at least
lencharacters long. -
match(
RegExp pattern, [String? errorMessage]) → void -
Instructs StringMust to check
whether the given value matches
pattern. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notBeEmpty(
[String? errorMessage]) → void - Instructs StringMust to make sure the given string is not empty.
-
toString(
) → String -
A string representation of this object.
inherited
-
validate(
String? value) → bool -
Validates
value. Returns whether the value is valid.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited