Hacker News new | past | comments | ask | show | jobs | submit login
Google's library for dealing with phone numbers (Java/JavaScript) (code.google.com)
190 points by kondro on Jan 5, 2011 | hide | past | favorite | 39 comments



Somewhat unrelated, but I've grown to dislike the Skype addon for Firefox because of its phone number recognition. It gets far too many false positives. Even numbers several digits short of being a phone number are often mistaken as one, throwing off the formatting of the page.


It's worse on the iPhone! It's hard to tell if a number is a genuine hyperlink or something the iPhone has recognised as a phone number.


Just tap and hold, you'll see which in about a second.


I know, but I'm lazy and I'd like to be able to know by looking at a link instead of tapping and holding each number for a few seconds (and then pressing the cancel button if it's a phone number).


Apple could put a little phone icon to the left or right of the auto-generated links. In my usage though phone numbers are very rarely linked (where would they go?), so when I see a linked one on an iOS device I assume it will trigger a phone call.


someone need to invent a html tag for that :)


<a href="callto://911">911</a> ?


Now I feel bad for not posting it here as well (I posted it on reddit a few days ago: http://www.reddit.com/r/java/comments/et5az/libphonenumber_g... ) :(

I often avoid posting java links to HN, thinking that the HN community is more focused on Rails / node.js / python. Guess I should reconsider :)

Funny how this intangible karma stuff affects me :)


And I regret not blogging about it on my personal blog and linking that here to generate traffic and potential subscribers there. LOL.

Of course, it may not have actually been a wasted opportunity as the (google.com) URL part of the title probably accounts for a large percentage of clicks.

P.S. I upvoted your comment to generate a little more karma as compensation.


Hehe. Not sure you should do that though (according to the HN guidelines, one should submit the original source) ;)

Thanks for the upvote, that's kind of you!

In retrospect, I shouldn't have "whined" in my previous comment. As the Facebook quote goes ("If you guys were the inventors of Facebook, you'd have invented Facebook"): had I wanted to post this on HN, I would have posted it on HN!

I'll try to post more links in the future (Java or otherwise), and stop trying to anticipate their success according to some pre-conceived notion of what the HN crowd likes: if I think it is interesting, someone else might like it as well ;)


It's very useful for my work. I upvoted you at Reddit too.


Found this today whilst I was looking for a solution to standardised formatting of phone numbers. I was hoping for a ruby solution, but this is an extremely complete library supporting formatting and validation for 228 countries/regions.


"extremely complete library"

I'm interested in how the completeness is defined, as the standards available are loose at best. I couldn't see by what measure they considered this work 'complete'.

That complaint aside, it's a great effort to see. Now to test it out...


"A direct port to Javascript is also available."

Did you happen to notice where this is?


It is in the SVN. README documents the usage.

http://code.google.com/p/libphonenumber/source/browse/#svn%2...



How much work would it take to make a complete ruby port?


Well... habermann24 (https://github.com/habermann24/libphonenumber-ruby) looks like he's started on a ruby port and he also has his phoney library which doesn't appear to use the same dataset and doesn't work properly for Australia.

I am planning on just using the Java version with JRuby - it will probably be faster than a pure ruby version anyway.


Not the answer you were looking for, but you could run the Java lib with JRuby, or use the JS lib with Ruby/V8 and "The Ruby Racer" (https://github.com/cowboyd/therubyracer)


Or python... I'm hacking together regexes for dealing with specific country formats in django right now... Is there a comparable python lib available?


I've looked around and haven't found a PHP port of this.

Given the usefulness of this library, I've been inspired to give it a go: http://github.com/damncabbage/libphonenumber-php

(Java --> PHP is tough going. Come back in a month. ;) )


This would be good for Twilio, which doesn't have any phone number validation methods in its libraries.


That always struck me as an odd omission.


Well, when you think about the amount of data collection required to reach this level of coverage I don't blame a smallish start-up like Twilio for not having a library.

After all, if you want to test to see if a number is valid, try and call it.


It's a daunting amount to approach, but it rarely takes more than an hour or two per country. I've been doing something similar for my current project, because I want to take phone numbers in national form and show them in both international and national forms.


So if you need to handle the 228 countries this lib handle, you only need 228 to 556 hours of work ...


  <nitpick>456</nitpick>


Well, given that I'm taking longer than that to collect my data for each country, it seems like a bargain!


This stuff is non-trivial. I'll guess that I have spent in excess of 50 hours working on just the UK data in the last couple of months.

The problem is this. Although there are hundreds of websites with UK area code lists, almost all of them are either incorrect, out of date, full of typos, or are generally unreliable. Even lists from "official" sources cannot be relied on with any degree of certainty. The obvious errors are easy to find and correct. It took a long time to find out there were many non-obvious errors and there are likely more errors still to be uncovered.


We're working on revamping our libraries and will most likely add something like this in a future release.


Fun fact: The swiss phone number they use in the example apparently is the phone number of Google's Swiss Office in Zürich.


I have been looking for similar lib in C\C++.


Awesome! I'm currently working on a project to deal with all sorts of phone numbers in bulk. I've already duplicated some of this in my own way, but I think it might come in handy for the rest.


This is pretty cool -- how do they deal with changes to the metadata, like when a country has a new code?


A code review tool is used to propose changes to the code and metadata and to review and comment on proposed changes.

When everyone is in agreement, the internal Google version is updated with the proposed changes.

Once testing is complete, the java code and metadata is pushed to the public version.

The final steps are to produce the javascript port, and on a less regular basis the .jar file in the "downloads" section is also updated.


invalid country code for 994 (Azerbaijan) tried both with 00 and without



thanks


994 is the correct country code; where are you trying to call from? If you're in the US or Canada, you need to dial the exit code first; for other countries, you might need other additional prefixes.

See http://www.howtocallabroad.com/ for more information.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: