Skip to content

.startsWith()

Passes when value.startsWith(prefix) is true. Case-sensitive.

StringValidator<O> startsWith(String prefix, {String? message, MessageBuilder? messageBuilder})
Parameter Type Meaning
prefix String The required prefix. params['prefix'].
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 missingPrefix. Default message: value does not start with "+". value is replaced by the field name when there is one.

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

final phone = l.string().startsWith('+');
phone.validate(input)+1-1
  1. valid: '+44 20 7946 0958'
  2. invalid: '020 7946 0958'value does not start with "+"