stringMatchesPattern function

IEskValidator stringMatchesPattern(
  1. Pattern pattern, {
  2. String? error,
})

Validates that the String matches the provided pattern

This validator also validates that the value is a String first So there's no need to add the isString validator when using this validator

Implementation

IEskValidator stringMatchesPattern(Pattern pattern, {String? error}) {
  return isType<String>() &
      validator(
        (value) => pattern.allMatches(value).isNotEmpty,
        (_) => error ?? 'String to match "$pattern"',
      );
}