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

Get region code requiring more digits that it should #30

Closed
Yhozen opened this issue Jun 18, 2019 · 3 comments
Closed

Get region code requiring more digits that it should #30

Yhozen opened this issue Jun 18, 2019 · 3 comments
Labels

Comments

@Yhozen
Copy link

Yhozen commented Jun 18, 2019

function extractRegionCode( phoneNumber )
{
if ( phoneNumber.charAt( 0 ) !== '+' || phoneNumber.length < 5 )
return null;
var firstOne = phoneNumber.substr( 1, 1 );
var firstTwo = phoneNumber.substr( 1, 2 );
var firstThree = phoneNumber.substr( 1, 3 );
var regionCode;
regionCode = PhoneNumber.getRegionCodeForCountryCode( firstOne );
if ( regionCode !== 'ZZ' )
return regionCode;
regionCode = PhoneNumber.getRegionCodeForCountryCode( firstTwo );
if ( regionCode !== 'ZZ' )
return regionCode;
regionCode = PhoneNumber.getRegionCodeForCountryCode( firstThree );
if ( regionCode !== 'ZZ' )
return regionCode;
return null;
}

As we can see on that snippet, to get the region code we need to write 4 digits but it's only taking into account the first 3, can we switch it to just 3?

@grantila
Copy link
Owner

Right, don't remember why, do you have a use case for only 4 characters? Are you detecting on-the-fly while people enter a phone number?

@Yhozen
Copy link
Author

Yhozen commented Jun 19, 2019

Yes I'm trying to show the corresponding flag as they type, and it's working but it's probably a better user experience to show asap

@grantila
Copy link
Owner

🎉 This issue has been resolved in version 2.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants