nameValidator static method

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

nameValidator to validate name

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

Implementation

static String? nameValidator(String? value, [String? errorMessage]) {
  RegExp regex = CustomRegEx.nameRegex;
  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  } else if (!regex.hasMatch(value)) {
    return errorMessage ?? 'Please enter a valid name';
  }
  return null;
}