acoutts / flutter_libphonenumber

Leverages libphonenumber to allow for asynchronous and synchronous formatting of phone numbers in Flutter apps. Includes a TextInputFormatter to allow real-time AsYouType formatting.
MIT License
60 stars 73 forks source link

Phone number is truncated #4

Closed Adam-Langley closed 3 years ago

Adam-Langley commented 4 years ago

Formatting the number "+642101234567" using "formatNumberSync" produces the output "+64 21 012 3456"

It should not drop any digits from the end. The expected output is

"+64 21 012 34567"

Testing using libphonenumber.appspot produces the correct output:

https://libphonenumber.appspot.com/phonenumberparser?number=%2B642101234567

emmaxCreative commented 3 years ago

I have the same problem with austrian numbers... were you able to solve this or is this still an issue ?

acoutts commented 3 years ago

This seems to work as expected as long as you select Mobile and National for this number:

Before formatting:

Screen Shot 2020-10-25 at 11 25 37 AM

After formatting (sync):

Screen Shot 2020-10-25 at 11 25 58 AM

Clicking parse after also

Screen Shot 2020-10-25 at 11 26 28 AM

confirms it's correct:

acoutts commented 3 years ago

When using the synchronous formatting it's based on the example numbers supplied from libphonenumber, and uses a mask from those numbers. That's why it's important to specify the mobile/fixe line and national/international settings correctly so it uses the right mask to format it.

acoutts commented 3 years ago
[CountryWithPhoneCode(
  countryName: New Zealand,
  regionCode: NZ, 
  phoneCode: 64, 
  exampleNumberMobileNational: 021 123 4567, 
  exampleNumberFixedLineNational: 03-234 5678, 
  phoneMaskMobileNational: 000 000 0000, 
  phoneMaskFixedLineNational: 00-000 0000, 
  exampleNumberMobileInternational: +64 21 123 4567, 
  exampleNumberFixedLineInternational: +64 3-234 5678, 
  phoneMaskMobileInternational: +00 00 000 0000, 
  phoneMaskFixedLineInternational: +00 0-000 0000)
]
acoutts commented 3 years ago

@emmaxCreative I moved your comment back to your issue to keep it on track with the Austrian number discussion 👍