matches<E> static method

Rule<String, E> matches<E>(
  1. RegExp pattern, {
  2. required E error,
})

Validates that the string matches the given pattern.

StringRules.matches(
  RegExp(r'^[a-zA-Z0-9_]+$'),
  error: 'Only alphanumeric and underscore allowed',
)

Implementation

static Rule<String, E> matches<E>(RegExp pattern, {required E error}) =>
    PredicateRule(
      predicate: (value) => pattern.hasMatch(value),
      error: error,
    );