.max()
Passes when value.length is at most maxLength. Throws ArgumentError for a negative length.
Signature
Section titled “Signature”StringValidator<O> max(int maxLength, {String? message, MessageBuilder? messageBuilder})Parameters
Section titled “Parameters”| 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.
Code generation
Section titled “Code generation”@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.
Example
Section titled “Example”final code = l.string().max(3);@HasMax(50) required String name, // l.string().max(50).required()code.validate(input)+1-1- valid:
'abc' - invalid:
'abcd'