verifyMatches function

bool verifyMatches(
  1. String actual,
  2. String pattern, [
  3. String? message
])

Verify that a string matches a regular expression.

Example:

verifyMatches(email, r'^[\w.]+@[\w.]+$', 'Invalid email format');

Returns true if the verification passed, false otherwise.

Implementation

bool verifyMatches(String actual, String pattern, [String? message]) {
  if (!RegExp(pattern).hasMatch(actual)) {
    final msg = message ?? 'Expected "$actual" to match pattern "$pattern"';
    _verificationFailures.add(msg);
    return false;
  }
  return true;
}