users dialing "local" numbers

58 views
Skip to first unread message

Daniel Pocock

unread,
Feb 2, 2017, 7:01:26 AM2/2/17
to libphonenumber-discuss

Hi all,

If a user dials a number such as "71357000" and we know the country code
and area code where the user is located (e.g. "44", "20" for a UK/London
number), can we give these details to libphonenumber and it constructs
the number in various formats, e.g. the output would be:

national number with "0" prefix for dialing in country => 02071357000

E.164 number => +442071357000


Which API methods should be called to do something like that?

Or does libphonenumber only support this for country codes and not the
individual area codes within countries?

Regards,

Daniel


Lara Rennie

unread,
Feb 2, 2017, 11:37:20 AM2/2/17
to libphonenum...@googlegroups.com
You would have to:
- concatenate area code+local number
- get the region code for the country calling code using getRegionCodeForCountryCode
- call parse() with these as arguments
- call format(). When you call format there are many different ways; you can ask for NATIONAL, E164 etc. 



--
You received this message because you are subscribed to the Google Groups "libphonenumber-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libphonenumber-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Pocock

unread,
Feb 3, 2017, 6:03:31 AM2/3/17
to libphonenum...@googlegroups.com
On 02/02/17 17:37, 'Lara Rennie' via libphonenumber-discuss wrote:
You would have to:
- concatenate area code+local number

Does anything in the API help with this first step?

In particular,

- recognizing that the user is dialing a "local" number (e.g. in some countries, if the number starts with "0", it is NOT local, otherwise it probably is)

- concatenating the area code with the local number - in most cases this is quite simple, joining two strings, but are there any unusual cases where digits have to be added or removed?

To unsubscribe from this group and stop receiving emails from it, send an email to libphonenumber-di...@googlegroups.com.

Lara Rennie

unread,
Feb 3, 2017, 11:45:01 AM2/3/17
to libphonenum...@googlegroups.com


3. feb. 2017 12.03 p.m. skrev "Daniel Pocock" <dan...@pocock.pro>:
On 02/02/17 17:37, 'Lara Rennie' via libphonenumber-discuss wrote:
You would have to:
- concatenate area code+local number

Does anything in the API help with this first step?

In particular,

- recognizing that the user is dialing a "local" number (e.g. in some countries, if the number starts with "0", it is NOT local, otherwise it probably is)

I'd do:
- did input start with a +? Then it really isn't a local number.
- else if parse && isValidNumber - continue - we're already good.
- else if isPossibleNumber is true - try prepending area code. If now isValidNumber says true, win! If not, but isPossibleNumber says true still, then it could still be right but maybe validity data is out of date. 

To pick a winner in this case where number with or without area code is never valid but always possible, you could get the national prefix for a country and see if the normalized number starts with that.
-- getNddPrefixForRegionCode(region, true)
-- normalizeDiallableCharsOnly(local_number)

Then test if the normalized string starts with the national prefix.

- concatenating the area code with the local number - in most cases this is quite simple, joining two strings, but are there any unusual cases where digits have to be added or removed?

 Indeed there are two sad cases one has to be aware of. If it's mobile and from Mexico or Argentina we need to add the mobile token too.  For Argentina you can add a 9 at the start if the area code doesn't start with 0, or else 15 between area code and local number. For Mexico just stick a 1 in front.

Clients shouldn't have to know this though!!

We could write a function to do this, but then you'd have to pass in "isMobile" and you might not even know this.

Ideally, parse() would know and fix this so you could just naively always concatenate the two. We have an outstanding feature request to do this and even for MX at least have the data; we might have it for AR too. However it's complex.

So short term you'll have to special-case those two countries, sorry!!!

(Note if you don't know if the number is mobile, we can't currently help you for these two countries. However, if you get it wrong and don't include the mobile token many things will still work because a lot of carriers will fix it for you.)



- get the region code for the country calling code using getRegionCodeForCountryCode
- call parse() with these as arguments
- call format(). When you call format there are many different ways; you can ask for NATIONAL, E164 etc. 
2. feb. 2017 1.01 p.m. skrev "Daniel Pocock" <dan...@pocock.pro>:

Hi all,

If a user dials a number such as "71357000" and we know the country code
and area code where the user is located (e.g. "44", "20" for a UK/London
number), can we give these details to libphonenumber and it constructs
the number in various formats, e.g. the output would be:

national number with "0" prefix for dialing in country => 02071357000

E.164 number => +442071357000


Which API methods should be called to do something like that?

Or does libphonenumber only support this for country codes and not the
individual area codes within countries?

Regards,

Daniel


--
You received this message because you are subscribed to the Google Groups "libphonenumber-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libphonenumber-discuss+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "libphonenumber-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libphonenumber-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages