customRegexValidation static method

bool customRegexValidation(
  1. String? text,
  2. String pattern
)

自定义正则验证

Implementation

static bool customRegexValidation(String? text, String pattern) {
  if (text?.isEmpty ?? true) return false;
  try {
    final regex = RegExp(pattern);
    return regex.hasMatch(text!);
  } catch (e) {
    return false;
  }
}