emostar / flutter-libphonenumber

libphonenumber plugin for Flutter
MIT License
47 stars 49 forks source link

getRegionInfo function determines prefix incorrect if phoneCode is 4 digits #12

Open kleyos opened 4 years ago

kleyos commented 4 years ago

hey. for countries with 4 digits code (e.g. 1242, 1246, 1284 etc) getRegionInfo returns always 1 for prefix

emostar commented 4 years ago

The library is returning getCountryCode() for this value.

The javadocs for the backend library are at: https://javadoc.io/static/com.googlecode.libphonenumber/libphonenumber/8.12.10/com/google/i18n/phonenumbers/Phonenumber.PhoneNumber.html#getCountryCode--

Do you know which function would return the 1242 instead of 1?

difelice commented 3 years ago

I don't think there is a function to get Country Code for multiple regions, you will get the "main" code:

In the case of multiple regions, the one designated in the metadata as the "main" region for this calling code will be returned

You could try to extract the rest of the code from the "national number", if not fall back to the original country code, but this is unstable: https://javadoc.io/static/com.googlecode.libphonenumber/libphonenumber/8.12.10/com/google/i18n/phonenumbers/PhoneNumberUtil.html#getLengthOfGeographicalAreaCode-com.google.i18n.phonenumbers.Phonenumber.PhoneNumber-

I tried this: https://codesandbox.io/s/libphonenumber-js-test-forked-erv5s?file=/src/index.test.ts

Thanks.