Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting phone numbers based on country code

I have a database with phone numbers which I would like to format according to the country code of the phone number.

The numbers are currently stored in the following format:

+[country_code][number] (like +4512345678)

What I need is some kind of library for javascript, that based on the country code can format the number according to the official national format (http://en.wikipedia.org/wiki/National_conventions_for_writing_telephone_numbers). Below are some examples of how some of the numbers could be formatted

+4512345678 => +45 12 34 56 78
+12892708970 => (289) 270-8970

I have found this Java-library here https://code.google.com/p/libphonenumber/, which bascially solves the problem. However I would like a simple Javascript-solution, which they actually demonstrate on their page, but I cannot find any official downloads to the file file they use, making me wonder if a better solution exists?

like image 416
user2849406 Avatar asked Oct 24 '13 09:10

user2849406


2 Answers

Use libphonenumber-js https://github.com/googlei18n/libphonenumber

It has all the required features.

Credit

like image 187
SaudiD3mon Avatar answered Sep 28 '22 00:09

SaudiD3mon


http://libphonenumber.googlecode.com/svn/trunk/javascript/i18n/phonenumbers/ - perhaps this is what you are looking for, in the same library?

like image 20
Sudipta Chatterjee Avatar answered Sep 27 '22 22:09

Sudipta Chatterjee