Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NANP toll-free calculation logic incorrect & outdated #110

Closed
percivalalb opened this issue Dec 8, 2022 · 0 comments · Fixed by #111
Closed

NANP toll-free calculation logic incorrect & outdated #110

percivalalb opened this issue Dec 8, 2022 · 0 comments · Fixed by #111

Comments

@percivalalb
Copy link
Contributor

Referring to the following:

=item is_tollfree
The number is free to the caller. 800, 844, 855, 866, 877 and 888 "area codes"
=cut
sub is_tollfree {
my $self = shift;
if(${$self} =~ /^(\+1)?8[045678]{2}/) { return 1; }
else { return 0; }
}

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.

percivalalb added a commit to percivalalb/perl-modules-Number-Phone that referenced this issue Dec 8, 2022
The regex used in the old implementation matches a superset of what it
should of. Specifically, it erroneously matches any number that starts
"+18" and then contains any 2 of the digits "045678" (not necessarily
the same digit). The 2 digits after the 8 should be the same.

For DrHyde#110
percivalalb added a commit to percivalalb/perl-modules-Number-Phone that referenced this issue Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant