Skip to content

.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.

StringValidator<O> cuid2({String? message, MessageBuilder? messageBuilder})
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.

@IsCuid2(), or the constant @isCuid2. Put the annotation on the constructor parameter or the field.

final id = l.string().cuid2();
id.validate(input)+2-1
  1. valid: 'tz4a98xxat96iws9zmbrgj3a'
  2. valid: 'a'
  3. invalid: '123'value must be a valid cuid2