Question

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?

Was it helpful?

Solution

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

It has all the required features.

Credit

OTHER TIPS

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

try jquery validate lib, it contains us and you can add your own validation.

http://jqueryvalidation.org/phoneUS-method

Another libphonenumber library (libphonenumber-js) rewrite of Google Android's libphonenumber library.

See a live example here.

https://catamphetamine.github.io/libphonenumber-js/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top