Skip to content

.min()

Passes when value.length is at least minLength. Throws ArgumentError when the validator is built with a negative length.

StringValidator<O> min(int minLength, {String? message, MessageBuilder? messageBuilder})
Parameter Type Meaning
minLength int The smallest accepted length. params['min'].
message String? Replaces the default error message.
messageBuilder MessageBuilder? Builds the message from the issue. message wins when both are given. See Message builders.

Code tooShort. Default message: value must be at least 8 characters long; 1 character long for a limit of 1. value is replaced by the field name when there is one.

@HasMin(n) on a String field. On a number field the same annotation means a minimum value. Put the annotation on the constructor parameter or the field.

final password = l.string().min(8);
password.validate(input)+1-1
  1. valid: 'hunter2hunter2'
  2. invalid: 'abc'value must be at least 8 characters long