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

How to differentiate phone numbers between countries, canada and usa seems to have same dial code. So a valid US number is being flagged to Canada flag? #154

Closed
imkiran opened this issue Feb 7, 2019 · 10 comments

Comments

@imkiran
Copy link

imkiran commented Feb 7, 2019

No description provided.

@pasevin
Copy link
Collaborator

pasevin commented Feb 7, 2019

Good point regarding the same dial code "+1"

google-libphonenumber library has a isValidNumberForRegion validation option, which if implemented in our library could solve this issue.

I've tested this on my build. @webcat12345 is there a specific reason you used isValidNumber(number) instead of isValidNumberForRegion(number, 'US') in ngx-intl-tel-input.validator.ts?

If no, I could replace it and deploy.

@imkiran
Copy link
Author

imkiran commented Feb 11, 2019

@pasevin @webcat12345 Even if you pass the country value to isValidNumberForRegion(number, 'US') you will still be getting the canada validated number value not the us number validation. Its because we are having dialCode 1 for four countries. It happens to pick the canada iso code since it is the first element in the array. I hope we should be dealing with areaCodes to pass this.
screen shot 2019-02-11 at 12 03 38 pm

@pasevin
Copy link
Collaborator

pasevin commented Feb 11, 2019

Oh, I understand now. You mean if I begin typing +1 415 ... it will automatically select Canadian flag instead of US. Is that right?

I was thinking this is about validation, but it's about the input behavior.

I'm currently swamped with work, so encourage anyone who has time to look into this.

I myself will look into this when I find the time. But no ETA.

@pasevin
Copy link
Collaborator

pasevin commented Feb 11, 2019

I looked into this quickly and I can see that the proper way would be to use this.phoneUtil.getRegionCodeForNumber(number) instead of what we do now.

BUT, it will identify and select the country only after the number has been entered fully.
Which is not ideal, but looks like there's no other built-in way.

I tested it on my build, and it works with US / CA differentiation.

So the only issue is that the flag will not change until the whole number is completed.

Is this acceptable? Any other ideas?

@imkiran
Copy link
Author

imkiran commented Feb 11, 2019

No the flag should ideally change as user keeps typing. That will be the right user experience.

@pasevin
Copy link
Collaborator

pasevin commented Feb 11, 2019

Then I guess, it will take longer to come up with a custom solution, which matches areaCode if multiple dialCode found.

nationalNumber starts with area code like so 415... so probably it must happen here.

@imkiran
Copy link
Author

imkiran commented Feb 11, 2019

Okay please let me know when we can have this fixed. It's a prime feature.

@pasevin
Copy link
Collaborator

pasevin commented Feb 11, 2019

Good news, I have a working solution. Will push and publish tomorrow ;)
screen recording 2019-02-11 at 02 33 53 2019-02-11 02_36_01

@imkiran
Copy link
Author

imkiran commented Feb 11, 2019

Great you are awesome.

pasevin added a commit that referenced this issue Feb 11, 2019
@imkiran
Copy link
Author

imkiran commented Feb 12, 2019

This is ontario canada number +1-613-555-0191 but the flag is still US. I have set 'enableAutoCountrySelect' to true. Can you please check it. I will reopen the issue.
screen shot 2019-02-12 at 12 20 30 pm
screen shot 2019-02-12 at 12 20 38 pm

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