.length()
Passes when value.length equals length. Throws ArgumentError for a negative length.
Signature
Section titled “Signature”StringValidator<O> length(int length, {String? message, MessageBuilder? messageBuilder})Parameters
Section titled “Parameters”| Parameter | Type | Meaning |
|---|---|---|
length |
int |
The only accepted length. params['length']. |
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 invalidLength. Default message: value must be exactly 3 characters long. value is replaced by the field name when there is one.
Code generation
Section titled “Code generation”@HasLength(n). Put the annotation on the constructor parameter or the field.
Example
Section titled “Example”final iso = l.string().length(3);@HasLength(2) required String countryCode, // l.string().length(2).required()iso.validate(input)+1-1- valid:
'abc' - invalid:
'abcd'