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.

Implemented types

Constructors

StringMust()

Properties

error String
The error message as a result of a failed validation. This is empty if the previous validation is passed.
no setteroverride
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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 len characters long.
hasMinLength(int len, [String? errorMessage]) → void
Instructs StringMust to make sure the given string is at least len characters 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