libphonenumber-csharp icon indicating copy to clipboard operation
libphonenumber-csharp copied to clipboard

HasCountryCode is always true

Open ilogixxDE opened this issue 1 year ago • 1 comments

Whatever I put into the number parser, in the result HasCountryCode is always true, the same for HasNationalNumber. What are the criteria for these parameters to become true? Assume we put in a DDI like 1234, I get back as a result +491234. But the number has definitly neither a CountryCode nor a NationalCode and my expectation would be that I get back simply 1234, HasCountryCode = false and HasNationalNumber = false. The same is true when putting in a national number, like 040-1234567. Then I would expect HasCountryCode = false, HasNationalNumber=true, while CountryCode would be the default county code, i my case Germany with 49. Maybe I misunderstood the features of the library, but my expectation is that I can put in whatever I like and I get proper HasXXX flags and number parts back.

Regards Christian

ilogixxDE avatar Aug 01 '22 07:08 ilogixxDE

My understanding of those fields is that they both would be internal however PhoneNumber is generated from a proto which means everything is public. PhoneNumberUtil.Parse always sets both if it does not throw. https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L2910 https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L3338. If a number is invalid !phoneNumberUtil.IsValid(number) the rest of the values don't provide much meaning. In most cases it is better calling phoneNumberUtil functions rather than interacting directly with the PhoneNumber object (GetNationalSignificantNumber, Format...., etc.).

twcclegg avatar Aug 01 '22 17:08 twcclegg

Closing due to inactivity.

twcclegg avatar Nov 27 '22 00:11 twcclegg