minLength static method

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

Validate minimum length

Implementation

static String? minLength(String? value, int minLength, {String? fieldName}) {
  if (value == null || value.isEmpty) {
    return '${fieldName ?? 'This field'} is required';
  }

  if (value.length < minLength) {
    return '${fieldName ?? 'This field'} must be at least $minLength characters';
  }

  return null;
}