phoneNumberValidator static method
phoneNumberValidator to validate a phone number Accepts phone numbers with or without country code, and without any special characters
validator: (value) => SimpleValidations.phoneNumberValidator(value, [errorMessage]),
Implementation
static String? phoneNumberValidator(String? value, [String? errorMessage]) {
RegExp regex = CustomRegEx.phoneRegex;
if (value == null || value.isEmpty) {
return errorMessage ?? 'Required';
} else if (!regex.hasMatch(value)) {
return errorMessage ?? 'Please enter a valid phone number';
}
return null;
}