Unable to parse 048 prefix for Northern Ireland in the Irish number plan
Number::Phone is unable to parse Irish (IE/+353) numbers using the special 048 prefix for Northern Ireland, which typically charges calls at the domestic rate but routes them international to the UK. Ctx: NI is part of the UK but geographicly part of Ireland.
$ perl -Ilib -Mv5.16 -MNumber::Phone::Lib -e 'my $pn = Number::Phone::Lib->new("+3534823456789"); \
say "parsed: ", $pn ? "true" : "false", " | valid: ", $pn && $pn->is_valid ? "true" : "false", " | formatted: ", $pn && $pn->format'
parsed: false | valid: false | formatted:
$ perl -Ilib -Mv5.16 -MNumber::Phone -e 'my $pn = Number::Phone->new("+3534823456789"); \
say "parsed: ", $pn ? "true" : "false", " | valid: ", $pn && $pn->is_valid ? "true" : "false", " | formatted: ", $pn && $pn->format'
parsed: false | valid: false | formatted:
Number::Phone is okey with the equivalent +44 number. (replacing "+353 (0) 48" with "+44 (0) 28").
$ perl -Ilib -Mv5.16 -MNumber::Phone::Lib -e 'my $pn = Number::Phone::Lib->new("+442823456789"); \
say "parsed: ", $pn ? "true" : "false", " | valid: ", $pn && $pn->is_valid ? "true" : "false", " | formatted: ", $pn && $pn->format'
parsed: true | valid: true | formatted: +44 28 2345 6789
libphonenumber was able to parse it: https://libphonenumber.appspot.com/phonenumberparser?number=%2B3534823456789
libphonenumber's support is mentioned in the comment here:
Another peculiarity is that 048 actually\nreplaces 00 44 28 when Irish people dial, allowing them to easily dial Northern\nIreland. We support these numbers here, although technically they are numbers for the\nUK."
The 048 range is listed here. I would at the very least expect Number::Phone::Lib to be able to parse +35348...
Oh, you can parse them if you provide the number with the leading 0 from the national format or provide the region.
$ perl -Ilib -Mv5.16 -MNumber::Phone::Lib -e 'my $pn = Number::Phone::Lib->new("+35304823456789"); \
say "parsed: ", $pn ? "true" : "false", " | valid: ", $pn && $pn->is_valid ? "true" : "false", " | formatted: ", $pn && $pn->format'
parsed: true | valid: true | formatted: +353 48 2345 6789
$ perl -Ilib -Mv5.16 -MNumber::Phone::Lib -e 'my $pn = Number::Phone::Lib->new("IE", "04823456789"); \
say "parsed: ", $pn ? "true" : "false", " | valid: ", $pn && $pn->is_valid ? "true" : "false", " | formatted: ", $pn && $pn->format'
parsed: true | valid: true | formatted: +353 48 2345 6789
I'm I being silly? The E.164 format should not contain the 0 trunk code for Ireland and so should be able to parse +3534823456789
Found this: https://github.com/DrHyde/perl-modules-Number-Phone/blob/251a4c2342f42cb20784b0c944a031c157bdefc8/t/number-phone-country.t#L164
https://github.com/DrHyde/perl-modules-Number-Phone/blob/251a4c2342f42cb20784b0c944a031c157bdefc8/build-data.country-mapping#L159
My guess would be because there is a special case to return the country as GB, this messes up the ability to actually parses the number as it tries to use the GB patterns? This potentially might cause issues for all the prefixes listed there which have country overrides.
You'll have a better idea of the potential fix here (I definitely think something needs fixing) .
- It might be better to treat
+3534823456789as an IE number usingNumber::Phone::StubCountry::IEand override the country returned when it is in the prefix 048? - Or prehaps make it so that the GB subcountry can handle the Ireland number
Aside:
This logic to identify the country breaks down when the number contains the country's trunk prefix. Hence why I could parse the +35304823456789 but not +353482345678.
- Suggested fix: (with the exception of Italy - maybe others I don't know of) if the number contains the trunk prefix (usually 0 right?) strip that before seraching in
$idd_codes.
Thank you for reporting this. I'm mostly offline at the moment but I'll take a look in the new year.
Of course. Me to (imminently). Merry Christmas!
Incidentally, the old mailing list that I had for this module has died, so I've set up a new one on Google groups: https://groups.google.com/g/number-phone