validateName static method

String? validateName(
  1. String? name, {
  2. int minLength = 2,
  3. int maxLength = 50,
})

Validates a name.

Returns null if valid, or an error message if invalid.

name The name to validate. Can be null. minLength Minimum name length (default: 2). maxLength Maximum name length (default: 50).

Implementation

static String? validateName(String? name, {int minLength = 2, int maxLength = 50}) {
  if (name == null || name.isEmpty) {
    return 'Name is required';
  }
  if (name.length < minLength) {
    return 'Name must be at least $minLength characters';
  }
  if (name.length > maxLength) {
    return 'Name must be less than $maxLength characters';
  }
  return null;
}