.cuid2()
Passes when the string is a lowercase letter followed by lowercase letters and digits. That is the whole CUID2 grammar, so any lowercase word passes. Add .length() if you generate CUID2s of a fixed length.
Signature
Section titled “Signature”StringValidator<O> cuid2({String? message, MessageBuilder? messageBuilder})Parameters
Section titled “Parameters”| Parameter | Type | Meaning |
|---|---|---|
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 invalidCuid2. Default message: value must be a valid cuid2. value is replaced by the field name when there is one.
Code generation
Section titled “Code generation”@IsCuid2(), or the constant @isCuid2. Put the annotation on the constructor parameter or the field.
Example
Section titled “Example”final id = l.string().cuid2();@IsCuid2() required String id, // l.string().cuid2().required()id.validate(input)+2-1- valid:
'tz4a98xxat96iws9zmbrgj3a' - valid:
'a' - invalid:
'123'