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