fieldLength static method
Validator to check if a field's length falls within a specified range.
max
: The maximum allowed length.min
: The minimum allowed length.
Implementation
static ValidatorEvent fieldLength({
int? max,
int? min,
}) {
return (value) {
var res = true;
var error = <String>[];
if (max != null) {
if (value.toString().length > max) {
res = false;
error.add('error.field.max#{$max}');
}
}
if (min != null) {
if (value.toString().length < min) {
res = false;
error.add('error.field.min#{$min}');
}
}
return FieldValidateResult(
success: res,
error: res ? '' : 'error.field',
errors: error,
);
};
}