in reply to Re: Regular expression for Fax numbers
in thread Regular expression for Fax numbers

That module is very buggy. It permits five digit numbers, which AFAIK no longer work anywhere in the US. It permits invalid numbers like 123-456-7890. And despite the name, it doesn't actually care whether a number is in the US or in, say, Jamaica. You should use my Number::Phone::NANP::US, which knows which numbers are valid or invalid in the numbering plan, as well as which numbers are assigned to the US and which to the various other countries.

What my code *won't* do for you though is find a phone number in a block of text.

  • Comment on Re^2: Regular expression for Fax numbers

Replies are listed 'Best First'.
Re^3: Regular expression for Fax numbers
by swampyankee (Parson) on Feb 12, 2009 at 14:04 UTC

    The only way of ensuring that a telephone number is in the US vs Canada or one of the Caribbean nations using the North American phone system is to maintain a list of area codes for the US vs anywhere else. Given that new area codes are being added all the time, any code would require a method of updating the list. And while "123-456-7890" may be invalid today, it could be valid in the future.


    Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

      Well, if you're going to keep a list of area codes, and reject numbers whose first three digits aren't on that list, why not maintain a list of exchange codes as well? I mean, if you're going to reject '123-456-7890' because '123' isn't a valid area code, shouldn't you also reject '212-555-7890', because '555' isn't a valid exchange code?

      Of course, keeping a list of exchanges per area, that still isn't the end. Not all exchanges connect 10000 numbers.

        Since I went to the website pointed to by beth, I know more than I ever wanted to about North American telephone numbers. About the only guarantee that seems to be present is that the area code (NPA) won't start with 1 or match /^[2-9]11/.

        I think that the answer to the crux of the OP's question is that there is no guaranteed manner of distinguishing North American (not just US) fax numbers from voice numbers. Indeed, the same line can be used for either at any time. There's also no coding scheme that distinguishes US from any other North American phone numbers: the US does not have a distinct country code, as does, say, the UK, nor can US area codes be distinguished from those of Canada by a regular expression.

        As to keeping a list of exchanges by area code, one can certainly do that, but I would suspect that this is going to be even more changeable than the list of area codes. The list of individual phone numbers will change even more rapidly than the list of exchanges.

        When I was doing software development in the market research industry (NOT TELEMARKETING), my then-employer contracted with more than one of the companies that actually maintain lists of residential vs business vs fax vs cell numbers so that our pollsters would call only residential numbers. The pollsters still called fax, cell, and business numbers by mistake, as the services couldn't keep up.


        Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

        I *do* keep a list of area codes (admittedly not 100% up to date, but I do try to keep it updated). I don't keep a list of exchange codes, because the information doesn't appear to be available in a convenient form.

        And the 123 area code isn't rejected because it doesn't exist, it's rejected because it's badly formed and such an area code can *never* exist in the current NANP.