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

isValidPhoneNumber throws exception instead of returning false #15

Open
elvisun opened this issue Mar 20, 2020 · 4 comments
Open

isValidPhoneNumber throws exception instead of returning false #15

elvisun opened this issue Mar 20, 2020 · 4 comments

Comments

@elvisun
Copy link
Contributor

elvisun commented Mar 20, 2020

When I passed "+1" to isValidPhoneNumber, it throws the following exception:

E/flutter (13120): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(NumberParseException, The string supplied did not seem to be a phone number., null)

isn't the point to return false when it's not a phone number?

I'm planning on adding a try catch block around this function, happy to submit a PR if approved, does that make sense?

@emostar
Copy link
Owner

emostar commented Apr 2, 2020

Yes, you are right. This function should never throw an exception, but only return the boolean value.

If you could create a PR for it, I would appreciate it a lot!

@elvisun
Copy link
Contributor Author

elvisun commented Apr 2, 2020

Thanks! PR in #18

@ClemaX
Copy link

ClemaX commented Oct 1, 2020

Hi @emostar, there is a similar issue for PhoneNumberUtil.getRegionInfo and .normalizePhoneNumber when using an invalid phone number. Is this expected behaviour? Should we validate the phone number before trying to call these methods, or should it return a default value on PlatformException?

@elvisun
Copy link
Contributor Author

elvisun commented Oct 1, 2020

Yeah I think getRegionInfo and normalizePhoneNumber needs the number to be valid, so throwing an exception is proper. You can either call isValidPhoneNumber first or have a catch block yourself to handle the exception (e.g. present error message back to user).

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