PhoneNumberKit icon indicating copy to clipboard operation
PhoneNumberKit copied to clipboard

Is it possible to parse phone numbers without their country code?

Open SpacyRicochet opened this issue 3 years ago • 2 comments

Is there a way to configure PhoneNumberKit in such so would parse a number without a country code but with the 0 prefix correctly?

Example; 0612345678 (for mobile phone numbers) or 0711234567 (for land lines) is how a Dutch user would enter their phone number, but it parses as an invalid phone number. However, +31612345678 and +31711234567 parse as expected.

SpacyRicochet avatar Jul 25 '22 21:07 SpacyRicochet

Hey @SpacyRicochet ,

I am afraid it is not possible by design. The metadata that PhoneNumberKit is using from Google relies on the country code. So there is also a default country code detection in PhoneNumberKit, which is trying to do some educated guess (based on the user SIM or the locale settings) on the used country code. if you want to check there is a demo page from Google: https://libphonenumber.appspot.com, which doesn't work without the country/region code.

petermolnar-dev avatar Aug 14 '22 20:08 petermolnar-dev

Hi @SpacyRicochet

Yes, it's possible, but you'll need to configure the default region to NL. If the user is already in the Netherlands, it should work out of the box, but if the number doesn't match the current locale, it will be invalid and the country code is needed.

In the website mentioned by @petermolnar-dev, if you set de field Default Country, it should work.

If my answer helped you feel free to close the issue. :)

bguidolim avatar Aug 18 '22 08:08 bguidolim

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Oct 18 '22 04:10 github-actions[bot]

Closing issue, as it looks like it's indeed not possible like @petermolnar-dev mentioned. Thanks for the answers!

SpacyRicochet avatar Oct 19 '22 07:10 SpacyRicochet