Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Badabum opened this issue Jul 5, 2016 · 3 comments

Comments

@Badabum
Copy link

Badabum commented Jul 5, 2016

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
Copy link

RupW commented Jul 29, 2016

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
Copy link
Author

Badabum commented Jul 30, 2016

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants