alphaCharactersWithSpaceValidator static method

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

alphaCharactersWithSpaceValidator to validate if a form field contains alphabets and space

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

Implementation

static String? alphaCharactersWithSpaceValidator(String? value,
    [String? errorMessage]) {
  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  }
  RegExp regex = CustomRegEx.alphaWithSpaceRegex;
  if (!regex.hasMatch(value)) {
    return errorMessage ?? 'Only alphabets and space is allowed';
  }

  return null;
}