-
Notifications
You must be signed in to change notification settings - Fork 63
International format returned although region code is defined #49
Comments
Hi @netgfx, sorry for the late reply. Please note that "as you type" formatting/parsing is not something that is supported by this plugin... Now, about the parsing of your number, I think that it's not linked to the code of this plugin, but more related to how the native libraries are doing the parsing. Maybe when you provide a region, the phone number doesn't expect to parse an international number... But again, the fact that you're doing a partial formatting/parsing, you might get unexpected results. |
Hello, I have only tested on iOS. The fix was to check if the number had >= 10 digits before attempting a parse. But as I stated I would expect the parsing to fail until a valid US number was provided. The "bug" here is that while I do provide a region it wrongfully attempts to parse "any" number and thus it finds a random international number of a totally unrelated country. |
Is there any way to better implement type-as-you-go or partial formatting found in both Many things are good about this library, but lacking solid support from either foundational classes for Partial formatting is causing me to pull out some hair and look for a different library! Can I help? |
I figured something better out. If the phone number starts with a It might be nice to build a method that allows you to extract the Region (Country) Code from a full or partial phone number. e.g. Adding this and having it run if the region parameter were optional or was passed an invalid value (like XQ or null or empty String '') would likely solve the OP's issue. When there's a leading e.g.
Basically ignore what
I found a much easier and faster way of type-as-you-go or "formatAsYouType" as libphonenumber calls it -- Look at the first answer here: https://stackoverflow.com/questions/60981448/flutter-textformfield-calling-future-from-textinputformatter I'm just calling |
@ooglek I think it'd be better if you opened a new issue for the as-you-type discussion, but
I'm not sure I understand here, what do you mean by the The ""as you type" formatting/parsing is not something that is supported" was at the time, now this is provided. |
For this:
await PhoneNumberUtil().parse("+17703228", regionCode: "US");
it returns
(268) 770-2832
for.international
and2687702832
for national. Which doesn't respond to a US number. I would expectregionCode
to make theparse
return invalid/null until a valid US number is provided.Note that I'm running this on text change so it is certainly not a whole number while the user types, but since there is a specific regionCode it shouldn't need to parse the number for other countries
The text was updated successfully, but these errors were encountered: