alphaNumericCharactersValidator static method
alphaNumericCharactersValidator to validate if a form field contains only alpha-numeric values
validator: (value) => SimpleValidations.alphaNumericCharactersValidator(value, [errorMessage]),
Implementation
static String? alphaNumericCharactersValidator(String? value,
[String? errorMessage]) {
RegExp regex = CustomRegEx.alphaNumericRegex;
if (value == null || value.isEmpty) {
return errorMessage ?? 'Required';
} else if (!regex.hasMatch(value)) {
return errorMessage ?? 'Only alpha-numeric characters are allowed';
}
return null;
}