alphaCharactersValidator static method
alphaCharactersValidator to validate if a form field contains only alphabets
validator: (value) => SimpleValidations.alphaCharactersValidator(value, [errorMessage]),
Implementation
static String? alphaCharactersValidator(String? value,
[String? errorMessage]) {
RegExp regex = CustomRegEx.alphaRegex;
if (value == null || value.isEmpty) {
return errorMessage ?? 'Required';
}
if (!regex.hasMatch(value)) {
return errorMessage ?? 'Only alphabets are allowed';
}
return null;
}