usernameOrDisplayNameValidator static method
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;
}