validatePhoneNumber static method
Validate a phone number based on the country's dial code.
Implementation
static bool validatePhoneNumber(String phoneNumber, String dialCode) {
Country? country = getCountryByDialCode(dialCode);
if (country == null) return false;
int length = phoneNumber.length;
bool lengthValid =
length >= country.phoneMinLength && length <= country.phoneMaxLength;
bool startingDigitsValid = country.startingDigits.isEmpty ||
country.startingDigits.any((digits) => phoneNumber.startsWith(digits));
return lengthValid && startingDigitsValid;
}