DrHyde / perl-modules-Number-Phone

Number::Phone and friends
24 stars 31 forks source link

NANP toll-free calculation logic incorrect & outdated #110

Closed percivalalb closed 1 year ago

percivalalb commented 1 year ago

Referring to the following:

https://github.com/DrHyde/perl-modules-Number-Phone/blob/d921df1bb7527fd4650cc1a58236f2e4a6d34834/lib/Number/Phone/NANP.pm#L303-L313

In the NANP only 8XX numbers are toll-free as stated in the perldoc. However the regex used in the implementation matches a superset of what it should. Specifically, it erroneously matches any number that starts "+18" and then contains any 2 of the digits "045678" (not necessarily the same digit).

That means numbers like "+1808xxxxxxx" are considered toll-free by this library when they are not. I've extracted the regex to demonstrate this:

$ perl -e 'my $ok = "+1808xxxxxxx" =~ /^(\+1)?8[045678]{2}/; print ($ok ? "toll-free\n": "standard\n")';
toll-free

In addition a new toll-free prefix "833" has been added which the regex does not currently cover.

https://en.wikipedia.org/wiki/Toll-free_telephone_number#United_States

Today, several prefixes are used: ... and 833 (since June 3, 2017)

There is potential for other prefixes in the future. So these should be checked regularly.

Area codes reserved for future expansion of the service include 822, 880 through 887, and 889.

I'll put together an PR to address these issues.