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

Invalid US number incorrectly identified as a Jamaica number #38

Open
abhatia1176 opened this issue Jan 17, 2024 · 1 comment
Open

Invalid US number incorrectly identified as a Jamaica number #38

abhatia1176 opened this issue Jan 17, 2024 · 1 comment

Comments

@abhatia1176
Copy link

The library incorrectly identifies an invalid USA phone number as Jamaica number.

Example:
phonenumber.ParseWithLandLine("+1 289 2999", "US")

Expected output: "". Actual output: +12892999. I believe that since the length matched Jamaica's number length (7), it matched it with the country Jamaica.

The issue is that despite the country being provided correctly in the input, the function tries to identify the ISO3166 by Number in the following lines, and the GetISO3166ByNumber function matches with Jamaica. I did not follow why the library tried to retrieve ISO3166 by phone number when the correct country (US) was already provided as input.

	if plusSign {
		iso3166 = GetISO3166ByNumber(number, landLineInclude)
	} else {
		if indexOfInt(len(number), iso3166.PhoneNumberLengths) != -1 {
			number = iso3166.CountryCode + number
		}
	} 
@andreyvit
Copy link

From what I understand, and it's often the desirable behavior, the provided country is just a fallback for phone numbers not in an international format. If a phone number is a valid international phone number, you often don't want to reject it. Say you have a customer traveling from Jamaica, they have a valid phone number, you can serve them even in US.

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