HasCountryCode is always true
Closed this issue · 2 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
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.).
Closing due to inactivity.