usernameOrDisplayNameValidator static method

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

usernameOrDisplayNameValidator to validate whtner the provided value is a valid username or display name

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

Implementation

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