phoneNumber static method
FormFieldValidator that requires the field's value to be a valid phone number.
Parameters:
regex
The regex pattern to match.errorText
The error message when the phone number is invalid.checkNullOrEmpty
Whether to check for null or empty values.
This regex matches international phone numbers.
- It supports optional country codes.
- It allows spaces, dashes, and dots as separators.
- It validates the number of digits in the phone number.
Examples: +1-800-555-5555, 1234567890
Implementation
static FormFieldValidator<String> phoneNumber({
RegExp? regex,
String? errorText,
bool checkNullOrEmpty = true,
}) => PhoneNumberValidator(
regex: regex,
errorText: errorText,
checkNullOrEmpty: checkNullOrEmpty,
).validate;