usernameOrEmailValidator static method

String? usernameOrEmailValidator(
  1. String? value, [
  2. String? errorMessage
])

usernameOrEmailValidator to validate either a valid email or a valid username (alphanumeric with underscore)

validator: (value) => SimpleValidations.usernameOrEmailValidator(value, [errorMessage]),

Implementation

static String? usernameOrEmailValidator(String? value,
    [String? errorMessage]) {
  RegExp regex = CustomRegEx.usernameOrEmailRegex;
  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  } else if (!regex.hasMatch(value)) {
    return errorMessage ?? 'Please enter a valid username or email address';
  }
  return null;
}