phone static method
Implementation
static Validator phone([String countryCode = 'NG', String? text]) {
return (String? value) {
if (value == null) {
return null;
}
PhoneNumberUtil phoneUtil = PhoneNumberUtil.instance;
try {
final phone = phoneUtil.parse(value, countryCode);
bool isValid = phoneUtil.isValidNumber(phone);
return !isValid ? (text ?? "Please enter a valid phone number") : null;
} on NumberParseException catch (_) {
return (text ?? "Please enter a valid phone number");
} catch (_) {
return (text ?? "Please enter a valid phone number");
}
};
}