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:
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 ->^\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
knock-wood
In reply to Re: phone number regex (new question)
by wolfi
in thread phone number regex (new question)
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |