regex static method

Validator<String?> regex(
  1. String pattern, {
  2. String? errorMessage,
  3. bool caseSensitive = true,
})

Check if the string has pattern pattern chars if string is not null and not empty.

Returns null if is valid.

Returns FieldBlocValidatorsErrors.regex if is not valid. Custom regex validator.

Implementation

static Validator<String?> regex(
    String pattern, {
      String? errorMessage,
      bool caseSensitive = true,
    }) {
  final regExp = RegExp(pattern, caseSensitive: caseSensitive);
  return (String? string) {
    if (string == null || string.isEmpty || regExp.hasMatch(string)) {
      return null;
    }
    return errorMessage ?? FieldBlocValidatorsErrors.regex;
  };
}