maxDigits<E> static method

Rule<String, E> maxDigits<E>(
  1. int max, {
  2. required E error,
})

Validates that the phone number has at most max digits.

PhoneRules.maxDigits(15, error: 'Phone number too long')

Implementation

static Rule<String, E> maxDigits<E>(int max, {required E error}) =>
    PredicateRule(
      predicate: (value) {
        final digits = value.replaceAll(RegExp(r'\D'), '');
        return digits.length <= max;
      },
      error: error,
    );