hasMaxLength method

void hasMaxLength(
  1. int len, [
  2. String? errorMessage
])

Instructs StringMust to make sure the given string is at most len characters long.

Implementation

void hasMaxLength(int len, [String? errorMessage]) {
  _validators.add((value) {
    if (value == null || value.length > len)
      return errorMessage ?? 'String is longer than $len.';
    return '';
  });
}