food for thought from a newbie on your regex... this worked for a few of my tests, but i haven't fully experimented w/it.

i also tried to condense this w/references, but the script would either fail (due to nested quantifiers) or i'd rec'v my 'sorry you goofed' statement... the few ref's i could use didn't save much space. So, if anyone has a better way to revise this - feel free.

my $number =~ /^\s*1?(\.|\-)?\s*((\(|\[|\{)?\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*(\)|\]\})?)?\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*\d\s*(\.|\-)?\s*$/

(i know, it's sooo ugly.)

Basically breaks down like this:

^\s* #start/optional spaces 1?(\.|\-)?\s* #an optional 1- or 1. with optional spaces ( (\(|\[|\{)? #an optional bracket ( or { or [ \s*(\.|\-)?\s* #space or optional . or - \d\s*(\.|\-)?\s* #digit optional . or - and spaces \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto (\)|\]\})? # choice of closing brackets )? # that section was optional \s*(\.|\-)?\s* #space or optional . or - \d\s*(\.|\-)?\s* #digit optional . or - and spaces \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto \d\s*(\.|\-)?\s* # ditto $ # nothing more allowed
it'll yield numbers w/ or w/out a leading "1" - w/ or w/out an area code (w/ or w/out parantheses) then seven digits - all of which can be separated by white-space, a dash, or a dot ->
1.(234]-567.8.9.0.0 should be readable. You could then run it thru a loop to get it into a format you prefered, if ya wished (prob just removing everything 'cept digits would be easiest.) It's tough to account for every format a user would try, but this would do most.

knock-wood


In reply to Re: phone number regex (new question) by wolfi
in thread phone number regex (new question) by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.