I am trying to format phone numbers using https://pypi.org/project/phonenumbers/ It is working. But is there a way I could verify if this would comply E.123/E.164 formatting ? Appreciate any help. https://en.wikipedia.org/wiki/E.123 https://en.wikipedia.org/wiki/E.164
def format_phone_number(contact):
phone_number = contact.get('phone_number')
country_code = contact.get('country')
if phone_number and country_code:
try:
country = pycountry.countries.get(alpha_2=country_code)
if country:
formatted_number = phonenumbers.format_number(
phonenumbers.parse(
phone_number, country.alpha_2
), phonenumbers.PhoneNumberFormat.INTERNATIONAL
)
return formatted_number
except (phonenumbers.NumberParseException, AttributeError):
pass
return None