I'm coming in late on this one, but I have 2 remarks on Jochem's
solution:
1. the dot doesn't need escaping in a character set. [ .-] should do it.
You hardly need escaping in sets as long as you choose the order of the
characters wisely.
2. I don't know if it matters, but the comment he made on ( and ) also
applies for the dots and hyphens. Can the be mixed? The regexp will
allow (200).200-0000 as a phone number too. You may need a lot more |
(ors) in there. The first thing you have to do is write down all
acceptable formats and start from there. If you ONLY accept the formats
below, I think the following regexp would do it:

^([2-9]\d\d([.-])[2-9]\d\d\2\d{4}|\([2-9]\d\d\)[ ]?[2-9]\d\d-\d{4})$

Pascal

> -----Original Message-----
> From: Jochem van Dieten [mailto:[EMAIL PROTECTED]
> Sent: 02 August 2004 20:18
> To: CF-Talk
> Subject: Re: Stupid telephone regex question
>
> Matt Robertson wrote:
> >
> > The regex *should* accept numbers formatted as such:
> >
> > 000-000-0000
> > (000) 000-0000
> > (000)000-0000
> > 000.000.0000
> >
> > where the zeroes represent a digit range from 2-9 in the first
> > position, of area code and prefix, and any digit in any other
> > position.
>
> How about:
> ^(\([2-9]\d{2}\)|[2-9]\d{2})[ \.-][2-9]\d{2}[ \.-]\d{4}$
>
>
> > \(?[2-9]\d\d\)?[ -]?[2-9]\d\d-\d{4}
>
> Don't use a style where you make the check for a ")" a differnet
> check from the check for a "(", that would allow unbalanced phone
> numbers such as "000) 000-0000". Always check them both at the
> same time so you get all or nothing.
>
> Jochem
>
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to