matches<E> static method

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

Validates the phone number against a custom pattern.

Use this for country-specific validation when built-in rules don't cover your needs.

PhoneRules.matches(
  RegExp(r'^\+44\d{10}$'),
  error: 'Invalid UK phone number',
)

Implementation

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