maxLength static method

Validator<String?> maxLength(
  1. int max, {
  2. String? errorMessage,
})

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;
  };
}