matchesPattern static method

void matchesPattern(
  1. String input,
  2. RegExp pattern,
  3. [String message = DEFAULT_MATCHES_PATTERN_EX]
)

Validate that the specified argument character sequence matches the specified regular expression pattern; otherwise throwing an exception.

Validate.matchesPattern("hi", new RegExp("^test\$"));

The syntax of the pattern is the one used in the {@link RegExp} class.

input the character sequence to validate, not null pattern the regular expression pattern, not null Throws ArgumentError if the character sequence does not match the pattern

Implementation

static void matchesPattern(String input, RegExp pattern,
    [String message = DEFAULT_MATCHES_PATTERN_EX]) {
  if (pattern.hasMatch(input) == false) {
    throw new ArgumentError(message);
  }
}