isValidPhone property
bool
get
isValidPhone
Checks if the string is a valid phone number.
Accepts international formats with optional + prefix.
Example:
'+1234567890'.isValidPhone; // true
'123-456-7890'.isValidPhone; // true
Implementation
bool get isValidPhone {
final phoneRegex = RegExp(
r'^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$',
);
return phoneRegex.hasMatch(removeWhitespace());
}