maxLength static method

String? maxLength(
  1. String? value,
  2. int max, {
  3. String? fieldName,
})

Validates maximum string length.

Implementation

static String? maxLength(String? value, int max, {String? fieldName}) {
  if (value == null || value.isEmpty) {
    return null;
  }

  if (value.length > max) {
    return '${fieldName ?? "This field"} must not exceed $max characters.';
  }

  return null;
}