Skip to content

.max()

Passes when value.length is at most maxLength. Throws ArgumentError for a negative length.

StringValidator<O> max(int maxLength, {String? message, MessageBuilder? messageBuilder})
Parameter Type Meaning
maxLength int The largest accepted length. params['max'].
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 tooLong. Default message: value must not be more than 3 characters long. value is replaced by the field name when there is one.

@HasMax(n) on a String field. On a number field it means a maximum value. Put the annotation on the constructor parameter or the field.

final code = l.string().max(3);
code.validate(input)+1-1
  1. valid: 'abc'
  2. invalid: 'abcd'value must not be more than 3 characters long