catamphetamine / libphonenumber-js

A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
https://catamphetamine.gitlab.io/libphonenumber-js/
MIT License
2.76k stars 218 forks source link

Some North American countries receive incorrect National Format when removing digits #451

Open meevo-ccaporrimo opened 7 months ago

meevo-ccaporrimo commented 7 months ago

Issue: When one of the affected area codes is used to populate a phone number and user backspaces to remove digits, if the backspace would cause phone number length to be 7 digits, regex pattern causes the "national format" to output with the area code duplicated.

The metadata regex patterns for the affected countries may be at fault. Their country code is actually +1 (North America) and the "area code" is the following 3 digits. Regex pattern should probably use pattern length of 10 for these to allow for the "area code" to be part of the full phone number (similar to Canada, US, Dominican Republic etc). Our findings show the regex has length of 7. Making the adjustment manually in the metadata file did stop this from happening.

Here's an example for American Samoa using appspot https://libphonenumber.appspot.com/phonenumberparser?number=6845551&country=AS image

The metadata file has this entry for American Samoa: "AS":["1","011","(?:[58]\\d\\d|684|900)\\d{7}",[10],0,"1",0,"([267]\\d{6})$|1","684$1",0,"684"]

The regex pattern we tested changing was ([267]\\d{6})$|1 which we changed to ([267]\\d{9})$|1 and the problem did not occur again

Full list of affected dialing codes / countries: