BetweenLengthValidator<T> class
A validator that checks if the length of a value is between minLength and maxLength.
The BetweenLengthValidator can be used with FieldControllers holding
values of types String
, List
, Map
or Set
. It ensures that the
length is between minLength and maxLength.
If the value is null
it is treated as valid by default.
Properties
- minLength: The minimum allowed length for the value.
- maxLength: The maximum allowed length for the value.
- message: An optional custom error message to display when invalid.
Example
FieldController<String> field = FieldController(
key: 'name',
validators:[BetweenLengthValidator(minLength:4, maxLength:6)],
);
// If field.value = 'Ana', validation fails.
// If field.value = 'João Pedro', validation fails.
// If field.value = 'Maria', validation passes.
See also
- FormyValidator, the base class for custom validators.
- ValidationResult, which describes the outcome of validation.
- FieldController, which holds the field value to be validated.
- Inheritance
-
- Object
- FormyValidator<
T> - BetweenLengthValidator
Constructors
- BetweenLengthValidator.new({String? message, required int minLength, required int maxLength})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxLength → int
-
The maximum allowed length for the value.
final
- message → String?
-
finalinherited
- minLength → int
-
The minimum allowed length for the value.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
call(
FieldController< T> controller) → ValidationResult -
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onValidate(
FieldController< T> controller) → ValidationResult -
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited