phonenumber icon indicating copy to clipboard operation
phonenumber copied to clipboard

Invalid US number incorrectly identified as a Jamaica number

Open abhatia1176 opened this issue 1 year ago • 1 comments

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
		}
	} 

abhatia1176 avatar Jan 17 '24 22:01 abhatia1176

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.

andreyvit avatar Mar 07 '24 09:03 andreyvit

@abhatia1176 @andreyvit Fixed. Please use v0.1.8

dongri avatar Aug 31 '24 15:08 dongri