getExampleNumber(String) returns same number for MF and BF.

254 views
Skip to first unread message

Heikki Hautala

unread,
Dec 22, 2020, 6:05:54 AM12/22/20
to libphonenumber-discuss
I created a test which creates an example number for every supported region code and verifies that PhoneNumberUtil:getRegionCodeForNumber(String) returns the same region code.

Looks like this is true for every supported region code except MF. And it looks like the example number for MF is the same as the example number for BF.

I looked at:

And found out that there is no entry for MF, but there is one for BF.

Regards,
Heikki Hautala

David Beaumont

unread,
Dec 22, 2020, 6:37:04 AM12/22/20
to libphonenum...@googlegroups.com
That's a test which you should not expect to pass in the general case. Regions with shared country calling codes do not always have clearly partitioned number spaces, so it's entirely possible that a number exists in both. For example, many NANPA numbers or GB numbers exist in multiple regions (and libphonenumber returns the "main" region in those cases).

libphonenumber has different example numbers for GP (590201234) and MF (590271234) which will map back to their expected regions.

Look at the regular expression in:
It excludes 59027xxxx for GP, meaning it's matched to MF.

What's stopping you using the get example number functionality in libphonenumber?

Cheers,
    David


--
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-di...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/libphonenumber-discuss/ecfc8887-59e4-43ee-9539-e17cd9d5cd79n%40googlegroups.com.


--
David Beaumont :: Îñţérñåţîöñåļîžåţîờñ Libraries :: Google
Google Switzerland GmbH., Brandschenkestrasse 110, CH-8002, Zürich - Switzerland

Heikki Hautala

unread,
Dec 22, 2020, 7:04:56 AM12/22/20
to libphonenumber-discuss
I'm making an android app that can automatically reject calls from blacklisted regions and allow calls from whitelisted regions specified by the user.
I want to make sure that the user of my app wouldn't:
  - miss calls from whitelisted regions and 
  - get calls from blacklisted regions 
because this lib detected the region of the incoming number wrong. 

So I guess there's no reliable way to achieve this?

David Beaumont

unread,
Dec 22, 2020, 7:56:59 AM12/22/20
to libphonenum...@googlegroups.com
The numbers with multiple regions associated to them are typically "service" numbers (toll free, premium rate etc.) and often non-commercial ones rather than personal numbers or private companies. I don't know if that helps in your case though.

If you want to find numbers which are *only* associated with a specific region ahead of time, it's possible but would involve some messing about with the metadata in its "raw" form.
However for your case, I think you can take the number and ask for all possible regions it could be in, and then decide what to do if there's more than one.

Also, maybe you don't expect many users to want to block "non main" regions without also blocking the main region (other than US/CA) so in reality it might not be an issue.

Cheers,
    David



Reply all
Reply to author
Forward
0 new messages