in reply to Phone reg expression

you might want to have a look at CPAN's Data::FormValidator. for a review, see markjugg's Data::FormValidator. if not a web app, try Regexp::Common

Update: for more in-depth info, try mojotoad's excellent Beast of the Number: Parsing the Feral Phone (this is one of my favorites--i knew i'd find it eventually)

~Particle *accelerates*

Replies are listed 'Best First'.
(jeffa) 2Re: Phone reg expression
by jeffa (Bishop) on Apr 18, 2003 at 17:36 UTC
    Hi particle.
    Regexp::Common was going to be my suggestion, but i can't figure out what Regexp::Common::URI::tel wants (or if that is even the right class to use):
    use Regexp::Common qw /URI/; while (<DATA>) { /$RE{URI}{tel}/ and print "$_ contains a telephone URI.\n"; } __DATA__ 555-5555 555-555-5555 (555) 555-5555
    any thoughts? anyone? :)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      tel:+12345 tel:+358-555-1234567 tel:456-7890;phone-context=213 tel:456-7890;phone-context=X-COMPANY-NET tel:+1-212-555-1234;tsp=terrifictelecom.com tel:+1-212-555-1234;tsp=terrifictelecom.com;phone-context=X-COMPANY-NE +T tel:+358-555-1234567;postd=pp22 tel:0w003585551234567;phone-context=+3585551234 tel:+1234567890;phone-context=+1234;vnd.company.option=foo tel:+1234567890;phone-context=+1234;vnd.company.option=%22foo%22 tel:+1234;option=%22!%22 tel:+1234;option=%22%5C%22%22 tel:+1234;option=%22%5C!%22 tel:+1234;option=%22bar%22 tel:+456-7890;phone-context=213;phone-context=213 tel:456-7890;phone-context=213;phone-context=213 tel:+123-456-789;isub=123(456) tel:+123456;postd=***

      For details, see RFC 2806.

      Abigail

        Que?

Re: Phone reg expression
by Abigail-II (Bishop) on Apr 18, 2003 at 22:58 UTC
    There are no patterns for phone numbers in Regexp::Common yet, for the simple reason I have not found a specification of phone numbers for any country yet.

    For instance, a regexp that allows for 7 or 11 digit phone numbers would be incorrect for the North America Plan, as that would reject for instance 911.

    Abigail

      For the obsessively curious, there's a lot of interesting (and apparently authoritative) information about U.S. and Canadian phone-number standards at NANPA, the North American Numbering Plan Adminstration. It covers arcana such as the so-called N11 numbers (911, 411, etc.), potentially valid area codes (/2-90-80-9/, except /\d11/, /37\d/, and /96\d/), vertical services codes (112?\d\d or \*2?\d\d), and so on. It even alludes to what will happen when North America eventually moves to 11-digit phone numbers (i.e., 4-digit area codes). Now there's a scary thought for anyone who's been writing phone-number validation code that assumes a 3-3-4 format.

              $perlmonks{seattlejohn} = 'John Clyman';