In applications sometimes is needed check and verify if a phone number is valid or possible if the number have all required digits to be valid for this purpose there are several options to tackle the problem like regular expressions for example to validate E.164 format, library like the [Google libphonenumber](http://Google libphonenumber) and API like the Twillio Lookup for something more complete.
for this post i created a small app for test a demo purpose using the [python port of the Google library](https://github.com/daviddrysdale/python- phonenumbers)
the app takes the country and the phone number then it validate and check against the python phonenumbers data.
check phone number app
In the form after select the country the calling code of the country is set
and then with the number is, the number is formatted in E.164 and send as JSON
in a request to a python micro-service running Python bottle and the library
Request:
{
"phone_number":"+40721234567",
"country_code":"RO"
}
Response:
{
"possible_number": true,
"number_data": "Country Code: 40 National Number: 721234567",
"valid_number": true,
"carrier_data": "Vodafone"
}
for the country data on the calling codes i found a excellent repository https://mledoze.github.io/countries/ with the data included in different formats very useful, for the country combo box i use react and semantic-ui.
the code for the form and the python micro-service are in github:
form and javascript: https://github.com/jms/check-phone-number
Python micro-service: https://github.com/jms/check-phone-number-service
References:
http://bottlepy.org/docs/dev/index.html
https://github.com/googlei18n/libphonenumber
https://github.com/daviddrysdale/python-phonenumbers
http://en.wikipedia.org/wiki/E.164
<https://www.twilio.com/help/faq/phone-numbers/how-do-i-format-phone-numbers-
to-work-internationally>
https://www.twilio.com/lookup