Comments (5)
Hi @netgfx, sorry for the late reply.
Does this occur on both platforms ?
Please note that "as you type" formatting/parsing is not something that is supported by this plugin...
It should be something that can be added though since it seems that PhoneKit
and libphonenumber
allows this mechanism. I haven't tried it nor implemented it, since I had no use for it at the time.
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.
from phone_number.
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.
from phone_number.
Is there any way to better implement type-as-you-go or partial formatting found in both libphonenumber
and PhoneNumberKit
without the massive amount of code in the Store
class?
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?
from phone_number.
I figured something better out.
If the phone number starts with a +
find the matching code as you type. Seems to work well, though I didn't do performance tests.
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. PhoneNumberUtil().getRegionCode(number);
Returns String ISO3166-2 Country Code
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 +
sign, it should indicate that you are specifying a full E.164 phone number and the Region (Country) code is implied and should NOT need to be passed separately.
e.g.
- input:
+12024003000
output:+1 (202) 400-3000
(if region is NOT specified) - input:
12024003000
output depends on region specified and how libphonenumber or PhoneNumberKit handles it - input:
6588887777
output again depends on region - input:
+6588887777
output:+65 8888 7777
region is Singapore (SG)
Basically ignore what region
is when the phone number leads with +
PhoneNumberUtil pnu = PhoneNumberUtil();
String numClean = '+6588887777'; // Replace with your variable with non-dialable chars removed
List<RegionInfo> regions = await pnu.allSupportedRegions();
RegionInfo found = regions.firstWhere(
(ri) =>
numClean.length > ri.prefix.toString().length &&
numClean.substring(1, ri.prefix.toString().length + 1) ==
ri.prefix.toString(),
orElse: () {
return null;
});
if (found != null) {
region = found.code;
}
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 PhoneNumberUtil().format(numClean, region);
in there and doing the fancy region matching if the number contains a + sign. Otherwise grabbing the region of the carrier, or assuming +1 US
.
from phone_number.
@ooglek I think it'd be better if you opened a new issue for the as-you-type discussion, but
Is there any way to better implement type-as-you-go or partial formatting found in both
libphonenumber
andPhoneNumberKit
without the massive amount of code in theStore
class?
I'm not sure I understand here, what do you mean by the Store
class? PhoneNumberEditingController
does not require any such class, see https://github.com/nashfive/phone_number/blob/master/example/lib/autoformat_page.dart .
The ""as you type" formatting/parsing is not something that is supported" was at the time, now this is provided.
from phone_number.
Related Issues (20)
- Receiving an error on validating any number on ios HOT 8
- General: Package throws PlatformException for every phone number HOT 4
- iOS 16.4 carrierRegionCode returns "--" HOT 2
- iOS 16.4 Phone Number validation all returns False. HOT 2
- [Field name or General]: update dependency on PhoneNumberCoreKit to latest HOT 6
- Formatter: format numbers without country codes
- [Country Code]: PhoneNumber().parse always returns US on Canada number in Android. iOS working as expected. HOT 2
- General: MTN Uganda Number prefix
- [CocoaPods]: PhoneNumberKit/PhoneNumberKitCore version differs repo from pub.dev HOT 3
- PhoneNumberUtil().validate is not validating many country codes HOT 1
- setup phonekit version is not correct '3.6.6' instead of 3.5.10 HOT 3
- Unable to validate number without region in Android. iOS works fine HOT 1
- PhoneNumber().parse always returns first matching country for countries having same dial code number in Android. iOS working as expected.
- Update the libphonenumber and phonenumberKit version
- Different parse results with the same number HOT 3
- Missing last character in onChange when using PhoneNumberEditingController and Strict mode
- RegEx (RegExp) for valid phone number HOT 2
- Very confusing validate function HOT 1
- MissingPluginException(No implementation found for method validate on channel com.julienvignali/phone_number) HOT 1
- Invalid number with valid format in IOS HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phone_number.