minLength function

String? Function(String) minLength(
  1. int n, [
  2. String? message
])

Creates a validator that fails when a string value has fewer than n characters.

Returns message (or 'Must be at least $n characters.' by default) when invalid, and null when valid.

final passwordField = BloomFormField(
  validators: [minLength(8, 'Password must be at least 8 characters.')],
);

Implementation

String? Function(String) minLength(int n, [String? message]) =>
    (v) => v.length < n ? (message ?? 'Must be at least $n characters.') : null;