Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: parsePhoneNumber omits countryCode when it wouldn't have to #106

Closed
Lemonexe opened this issue Sep 14, 2023 · 1 comment
Closed

Bug: parsePhoneNumber omits countryCode when it wouldn't have to #106

Lemonexe opened this issue Sep 14, 2023 · 1 comment

Comments

@Lemonexe
Copy link

Version 5.10.0

Description

I have noticed cases of unexpected behaviour of parsePhoneNumber, where it successfully detects a country calling code, as evidenced by the fact that it returns regionCode, the two-letter ISO country code, but it does not return a countryCode, the calling code itself, as it normally would.

It happens when the input is just the calling code, and between 0 to 2 numbers.

The countryCode can be mapped from regionCode by using getCountryCodeForRegionCode, so it is not a dealbreaker, just an inconvenience.

Steps to reproduce

Returns both properties: ✅

const { countryCode, regionCode } = parsePhoneNumber('+1555444333')
countryCode -> 1, regionCode -> 'US'

Does not return countryCode ❌ :

const { countryCode, regionCode } = parsePhoneNumber('+1')
countryCode -> undefined, regionCode -> 'US'
@grantila
Copy link
Owner

"+1" is not a valid phone number, it finding the region code is more of an interesting coincidence than something technically supported. The code internally only does a reverse lookup once a real phone number is found (because it might actually not be US just because it starts with "+1").

Use the getRegionCodeForCountryCode if you want to convert +1 to US and getCountryCodeForRegionCode for the other way around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants