MaxAgeValidator class
A validator that checks if the age calculated from the value date is less than or equal to maxAge.
The MaxAgeValidator can be used with FieldControllers holding
values of type DateTime. It ensures that the
calculated age does not exceed maxAge.
If the value is null, it is treated as valid by default.
Properties
- maxAge: The maximum allowed age calculated from the value date.
- message: An optional custom error message to display when invalid.
Example
FieldController<DateTime> field = FieldController(
key: 'date',
initialValue: DateTime(2025, 7, 12)
validators: [MaxAgeValidator(18)],
);
// If field.value = DateTime(2000, 7, 12), validation fails.
// If field.value = DateTime(2010, 7, 12), 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<
DateTime> - MaxAgeValidator
Constructors
- MaxAgeValidator(int maxAge, {String? message})
Properties
Methods
-
call(
FieldController< DateTime> controller) → ValidationResult -
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onValidate(
FieldController< DateTime> controller) → ValidationResult -
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited