twcclegg/libphonenumber-csharp

Parsing phone number as valid when it starts with _

PeteMcGann opened this issue · 9 comments

In order to validate a phone number the library requires a PhoneNumber instance which (in my case) is created using:
var phoneNumber = phoneUtil.Parse(number, "GB");

I then test the number using this code:

return phoneUtil.GetNumberType(phoneNumber) == PhoneNumbers.PhoneNumberType.MOBILE;

Unfortunately, if a phone number starts with an underscore the Parse function will ignore it and parse the number as if it wasn't there, which in turn means the number is considered valid when it isn't.

I believe #184 should resolve the issue. Presuming that, the change should be out in the 8.12.24 release.

Perfect thank you!

By any chance do you have an ETA on v8.13.24?

Probably pretty soon, release schedule follows https://github.com/google/libphonenumber/releases

I just installed v8.13.24 and unfortunately I have the same issue - when a number starts with _ the phoneUtil.Parse(number, "GB") method removes it, and hence it passes validation - am I doing something wrong?

Sorry, I’ve been out of town. Fix didn’t get merged in for 8.13.24, it will be in 8.13.25 which should be able to be released Sunday.

Ok no problem, thanks.

So v8.13.25 is out, and the logic for this better matches the Java version; however I overlooked that the Java version https://libphonenumber.appspot.com/phonenumberparser?number=_%2B14429994455 a preceding _ does not change the behavior.
I could add something to https://www.nuget.org/packages/libphonenumber-csharp.extensions/ but would need a more generalized use case and name for it, also using the extension library can make namespacing annoying and I don't personally consume it.

Thanks for that, much appreciated - I've modified my codebase to just remove anything other than a + from the beginning of a number before validating it, but this will come in handy anyway. Cheers.