maxLength static method
Check if the string
has max max
chars
if string
is not null and not empty.
Returns null
if is valid.
Returns FieldBlocValidatorsErrors.maxLength if is not valid. Max length validator.
Implementation
static Validator<String?> maxLength(int max, {String? errorMessage}) {
return (String? string) {
if (string == null || string.isEmpty || string.length <= max) {
return null;
}
return errorMessage ?? FieldBlocValidatorsErrors.maxLength;
};
}