minLength static method

String? Function() minLength(
  1. String value, {
  2. String? errorMessage,
  3. int minLength = 8,
})

Returns a validation function that checks if the input value meets a minimum length requirement.

The validation function will return an error message if the value's length is less than the specified minLength, otherwise it returns null indicating the value is valid.

value: The input value to validate. errorMessage: The error message to display if the validation fails. If not provided, a default message is used. minLength: The minimum required length for the input value. The default is 8.

Implementation

static String? Function() minLength(
  String value, {
  String? errorMessage,
  int minLength = 8,
}) {
  return () {
    if (value.length < minLength) {
      return errorMessage ?? 'Please enter at least $minLength characters.';
    }
    return null;
  };
}