Library to get canonical phone number
pip install canonical-phone==0.0.10
Convert given phone number into a string with hiphenated phone number with country code. Default is assumed to be Indonesian number.
pip install canonical-phone==0.0.6
from canonical_phone.phone import canonical_number
phone_no = canonical_number(phone) # If invalid, returns False
if not phone_no:
raise Exception("invalid phone number")
[
{
"input": "62-8734878374",
"output": "62-8734878374",
},
{
"input": "628734878374",
"output": "62-8734878374",
},
{
"input": "8734878374",
"output": "62-8734878374",
},
{
"input": "84-8734878374",
"output": "84-8734878374",
},
{
"input": "91-8734878374",
"output": "91-8734878374",
},
{
"input": "848734878374",
"output": "62-848734878374",
},
{
"input": "848734878374",
"output": "84-8734878374",
"has_country_code": True,
},
{
"input": "848734878374",
"output": "62-848734878374",
"has_country_code": False,
},
{
"input": "91848734878374",
"output": "91-848734878374",
"has_country_code": True,
}
]