Closed xsawyerx closed 10 years ago
If you've just got the area code then you could append '555 3333' or something similar to make a valid number. Does that help?
First of all, that would be ignoring the simple problem that the regex was too strict. Saying "let's give it fake input just to make it match the first digits" is a little silly.
Second of all, I had to do a back-tracking recursive search as well. I would start with a number that failed to match, the removed digits till it did. That will fail that because I needed to reduce digits, not add fake ones.
Is there a reason why the regex must be this strict? I should mention that this would, without a doubt, force me to fork this module, just for a single regex char. :/
Is it impossible to make it optional?
It's not impossible, but it's hard. The assumption that it's dealing with complete phone numbers is baked in all over the place. Getting past that check, you'll end up a bit later in the Number::Phone::NANP constructor, which does a more rigorous validity check on the first four digits, for example. And if you code your way around that, I wouldn't want methods like areacode() and subscriber() to return bogus results - the empty string is not a valid subscriber number, for example, and nor is 31 in the NANP if you only supply the first five digits. And finally I really don't want the NANP to be any more of a special case than it is already.
I'd accept a patch that has tests demonstrating that it works for the US, Jamaica, UK, Isle of Man, and Germany - that should cover all the different ways in which objects get created. It should contain a new method 'is_incomplete()' that returns 1 if an object represents an incomplete number and 0 otherwise, and things like areacode() and subscriber(), where implemented, should behave appropriately.
I just had a mailing list created for Number::Phone users: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/number-phone
Since I don't have full phone numbers, a lot of matching I try don't work because the phone regex requires both NPA and NXX digits. I've made the NXX digits optional and that makes all the difference.
I've separated this into a different pull request (and branch) for convenience.