nameValidator static method
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;
}