erezak / libphonenumber-csharp

Forking original c# port
Apache License 2.0
198 stars 79 forks source link

Invalid phone string parsing is not throwing exception or seting number state to invalid #23

Open Badabum opened 8 years ago

Badabum commented 8 years ago

I've tried to use this lib, but faced some weird (as for me) behavior. I have string with wrong telephone number +38093sdaf342, 380 is a code of Ukraine, but any non-digit characters is not allowed in Ukrainian numbers. Here is the function where I try to validate this number.

public bool IsValidPhoneNumber(string number,string regionCode)
        {
            var utils = PhoneNumberUtil.GetInstance();
            var phoneNumberInstance = utils.Parse(number,regionCode);
            return utils.IsValidNumber(phoneNumberInstance);
       }

Passed params to function number=+38093sdaf342, regionCode="UA". Ive seen that in created byParsefunction object propertyNationalNumber` is set to 937323342. Why is it so? I thought that this number must be validated as invalid cause it contains not only digits. Is it a bug or an expected behavior?

RupW commented 8 years ago

That does look wrong, but note that on the usual phone keypad 7=PQRS, 3=DEF, 2=ABC: so you'd turn SDAF into 7323 as you saw. (I think that is or was common in the US - they'd advertise numbers like "1 800 WDISNEY" and you'd dial 1 800 9247639 etc.) So it does look a deliberate transform, although I'm surprised it's on by default.

Badabum commented 8 years ago

@RupW , yup, in my opinion this conversion must be one of the latest conditions during validation process, or even different method which you can use when you need to perform such conversion.

fatih905 commented 7 years ago

Hope someone helps Use string newNumber = PhoneNumberUtil.NormalizeDigitsOnly("+38093sdaf342");