8

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?

user2849406
  • 195
  • 1
  • 1
  • 6

4 Answers4

3

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

It has all the required features.

Credit

SaudiD3mon
  • 121
  • 6
1

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

Sudipta Chatterjee
  • 4,592
  • 1
  • 27
  • 30
0

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

http://jqueryvalidation.org/phoneUS-method

Prog Mania
  • 615
  • 9
  • 14
  • It doesn't look like that will solve the problem. What I really need is some kind of library that can do that automatically. On top of that it looks like the link you provided only validates the input, but cannot format it? – user2849406 Oct 24 '13 at 09:52
0

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

See a live example here.

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

Penny Liu
  • 15,447
  • 5
  • 79
  • 98