matches method Null safety

Validator matches(
  1. RegExp regExp,
  2. {String message = "Validator.matches"}
)

Returns a Validator that accepts a value that has a match in regExp.

If the value is null, it is treated as an empty String.

Implementation

Validator matches(
  RegExp regExp, {
  String message = "Validator.matches",
}) {
  return add(
    (value) => regExp.hasMatch(value ?? "") ? null : message,
  );
}