Detecting Country

1,280 views
Skip to first unread message

Nolan Dubeau

unread,
Dec 21, 2011, 4:24:29 PM12/21/11
to libphonenum...@googlegroups.com
Hi folks,

With libphonenumber is there a method available whereby I can simply input a telephone number and it would tell me the country/locale that it belongs to?  We currently have an app that does not have a country selection, only a phone number field.  I'm looking for a way to dynamically detect the country.

Thanks!

Nolan




Lara Rennie

unread,
Jan 9, 2012, 7:11:27 AM1/9/12
to libphonenum...@googlegroups.com
Hey,

If someone has started the number with a + then you can parse the number with a region code of ZZ, and then ask for the region code of that parsed number. (It's something like getRegionCodeForNumber)

If they haven't, then you have little hope of working it out. The same phone number is valid in very many countries. If you can guess the country in some way (maybe using some data about the user?) then you can try parsing it with that country code, and see if it is valid or not, but it might still be incorrect. You could try parse + validate on all regions but then you'd just end up with a list of potential countries, so that probably wouldn't be so helpful for you.

Lara

2011/12/21 Nolan Dubeau <no...@guard.ly>

Nolan Dubeau

unread,
Jan 9, 2012, 7:28:56 AM1/9/12
to libphonenum...@googlegroups.com
Thanks Lara 

I will give that a shot.  

Nolan Dubeau

Sent from my Commodore-64
Load *.*,8,1
Reply all
Reply to author
Forward
0 new messages