DrHyde / perl-modules-Number-Phone

Number::Phone and friends

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The NANP areacode 300 treated as valid

percivalalb opened this issue · comments

Area Code 300 has not been assigned for use by the North American Numbering Plan Administrator.

From: https://www.areacodehelp.com/where/area_code_300.shtml

Number::Phone seems to be able to parse it (it is a possible future phone number) but then also says it is currently valid:

$ perl -MNumber::Phone -e 'my $p = Number::Phone->new("+1300-555-0000"); print $p->is_valid, "\n";'
1

The libphonenumber implementation is unable to parse it - which is what I would have expected.

$ perl -MNumber::Phone::Lib -e 'my $p = Number::Phone::Lib->new("+1300-555-0000"); print $p // "undef", "\n";'
undef

Number::Phone distinguishes when it can between valid (ie, potentially allocatable) and allocated numbers. Number::Phone::Lib, like libphonenumber, does not. The validity rules for the NANP are here:

$cache->{$number}->{is_valid} = (
$digits{A} >= 2 && $digits{A} <= 9 &&
$digits{D} >= 2 && $digits{D} <= 9 &&
$digits{A}.$digits{B} ne '37' &&
$digits{A}.$digits{B} ne '96' &&
$digits{B}.$digits{C} ne '11'
) ? 1 : 0;
.

That rule could probably be tightened up a bit - for example, 307 911 1234 is invalid. But I'm not sure of exactly what the rules are for the D/E/F digits. For the 307 area code, I believe that 7 digit local dialling is permitted (maybe even required?) and so 911 is obviously not a valid CO code, but for an area code like 416 which is overlaid with several other area codes I have no idea whether 7 digit dialling is allowed when calling another 416 number (in which case the 911 CO is clearly invalid), or whether 10 digit dialling to other 416 numbers is allowed as well as 7 digit dialling, or whether 10 digit dialling is required (and if it is whether the 911 CO is now valid as it can't appear at the start of a dialled subscriber number). I haven't been able to find any reliable-looking data source for this.