isValidPhoneNumber method
Validates a phone number format for WhatsApp.
phoneNumber
is the phone number to validate.
Returns true if the phone number is valid, false otherwise.
Implementation
bool isValidPhoneNumber(String phoneNumber) {
// Basic validation: remove non-digits and check length
final digits = phoneNumber.replaceAll(RegExp(r'[^\d+]'), '');
// Phone number should have at least country code and 7 digits
if (digits.length < 8) return false;
// Should start with + or country code
if (!digits.startsWith('+') && !RegExp(r'^[1-9]').hasMatch(digits)) {
return false;
}
return true;
}