Skip to content

.contains()

Passes when value.contains(substring) is true. Case-sensitive.

StringValidator<O> contains(String substring, {String? message, MessageBuilder? messageBuilder})
Parameter Type Meaning
substring String The text that has to appear. params['substring'].
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 missingSubstring. Default message: value does not contain "@". value is replaced by the field name when there is one.

@Contains(s). Put the annotation on the constructor parameter or the field.

final handle = l.string().contains('@');
handle.validate(input)+1-1
  1. valid: '[email protected]'
  2. invalid: 'a'value does not contain "@"