Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Regular expression for Fax numbers

by dxxd116 (Beadle)
on Feb 12, 2009 at 09:00 UTC ( #743250=perlquestion: print w/replies, xml ) Need Help??
dxxd116 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, Monks: Does anyone know the regular expression pattern for US fax numbers? I am developing an application requiring this regular expression. I though phone number regular expression and fax number regular expression are similar. Maybe I am wrong and who know the differences? Thank you in advance.

Replies are listed 'Best First'.
Re: Regular expression for Fax numbers
by JavaFan (Canon) on Feb 12, 2009 at 09:34 UTC
    There's no difference between phone and fax numbers. To make a regular expression, you'd have to ask yourself a couple of questions:
    • Do you require an area code, or will 7 digits be acceptable? Do you want to validate the area code as well?
    • In the US, it's not uncommon to use letters instead of digits. Is your regexp going to allow that?
    • Do you insist on separators? Are the optional? Forbidden? If they are separators, can they be dashes? Spaces? Either, but not mixed? Allowed elsewhere than the standard 3-3-4 grouping? Can you have parenthesis around the area code?
    • Do you require a leading 1? Is it optional? Do you allow the international '+' prefix?
    • What about extensions? Allowed? If so, for how many numbers?
    • It's possible to hook in a fax into a 911 dispatch center, making it a 'fax number' as well. Are you going to allow that as well?
    Depending on the answers, your regexp can be as simple as /1[0-9]{10}/, or something far more complex.


Re: Regular expression for Fax numbers
by ELISHEVA (Prior) on Feb 12, 2009 at 09:31 UTC
    You can find more than you ever wanted to know about formats for phone and fax numbers across the USA, Canada, and Mexico at North American Dialing Plan (NADP) Administration - start with the sidebar menu item for numbering resources.

    Best, beth

Re: Regular expression for Fax numbers
by GrandFather (Sage) on Feb 12, 2009 at 09:35 UTC

      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.

        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

Re: Regular expression for Fax numbers
by ww (Archbishop) on Feb 12, 2009 at 11:43 UTC

    Regular Expressions have nothing to do with the question asked because there is no US standard for distinguishing "fax numbers" from other POTS line dedicated to data, nor from voice lines.

    Consider your home telephone line(s):

    • If you have a fax (hardware or software) attached, is that a fax number?
    • If that line is also used for oral communications, is it a fax line?
    • Is it still a fax line if you installed it for use with a fax machine and have kept it as an extra voice line since you turned off the machine?

    JavaFan and others have made this point in various manners.

    The question is moot or needs refinement.

      The OP may not be from the US. He or she may have also realized that in some places mobile phones and land lines have distinct numbers (this is certainly the case in Israel where specific "area codes" are reserved for use by mobile phone companies) and may be wondering if the same extends to voice/fax.

      As for your examples, they may or may not apply in his or her home country. When I first moved to Israel I was amazed at how differently the telcom services were bundled here than in the States where I grew up. Things that I thought were distinct (e.g. voice mail) were integrated into my phone services. Things that I thought were all-in-one required special flags to be placed on the account. Faxes send out an easily recognizable sound pattern - it is not at all unreasonable to think that in some countries, that signal will be transmitted only from certainly specially designated lines.

      So in my opinion, better to ask than not. Somebody is probably paying a lot of money for this software. Perhaps you could help him/her out by guiding him/her in refining the question?

      Best, beth
      Former telcomm data analyst (many, many years ago)

Re: Regular expression for Fax numbers
by matze77 (Friar) on Feb 12, 2009 at 09:32 UTC

    I dont know the exact format for US-Fax numbers, but in germany it is common to write it in more than one "fashion".
    e.g. 040-1234567, 040/1234567, or the international version which applies for you too (there the "0" from 040 is removed) ?: +49401234567.
    Maybe this is similar for US? First thing would be to see what are common, allowed forms of the fax-number then build the regex i would suggest.
    Update: People might even write it like these: 040/1234-67 or 0 40/ 12 34 67 ... So i think it could be (like others mentioned) getting complex to match all these, maybe some "simple form" could only check for allowed signs (-, /, whitespace , +, digits ...) so that no letters are used at least?

    hth MH

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://743250]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2018-03-24 05:21 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (297 votes). Check out past polls.