invalidFormat method

String invalidFormat(
  1. String input,
  2. String regexPattern, {
  3. String? name,
  4. String? message,
  5. bool caseSensitive = true,
  6. bool multiline = false,
})

Throws an ArgumentError if input doesn't match the regexPattern. Returns input otherwise.

Implementation

String invalidFormat(
  String input,
  String regexPattern, {
  String? name,
  String? message,
  bool caseSensitive = true,
  bool multiline = false,
}) {
  RegExpMatch? match = RegExp(regexPattern).firstMatch(input);
  if (match == null) {
    throw ArgumentError.value(
        input, name, message ?? 'Input was not in required format');
  }

  return input;
}