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

How to support multiple mask? #13

Closed stwonary closed 3 years ago

stwonary commented 3 years ago

Some countries have multiple mobile formats. Austria and Bulgaria for example.

+43 6604 856532 +43 6604 85653

Validation Results
Result from isPossibleNumber() true
Result from isValidNumber() true
Phone Number region AT
Result from getNumberType() MOBILE

If I override the phone format, the one with fewer digits is detected as an invalid format. Any idea how can I support both formats?

await FlutterLibphonenumber().init(overrides: {
    'AT': CountryWithPhoneCode(
      phoneCode: '43',
      countryCode: 'AT',
      exampleNumberMobileNational: '06643 123456',
      exampleNumberFixedLineNational: '01 234567890',
      phoneMaskMobileNational: '00000 000000',
      phoneMaskFixedLineNational: '00 000000000',
      exampleNumberMobileInternational: '+43 6643 123456',
      exampleNumberFixedLineInternational: '+359 2 123 4567',
      phoneMaskMobileInternational: '+00 0000 000000',
      phoneMaskFixedLineInternational: '+00 0 000000000',
      countryName: 'Austria',
    )
  });
acoutts commented 3 years ago

Ah yes, this is not yet implemented, but PRs are welcome!

acoutts commented 3 years ago

This should now be possible with the latest version and using the additionalDigits parameter to the formatter.