Checking and validating phone numbers


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 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

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



    "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 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:

Python micro-service: