Re: [PHP] Regex (Phone Number)

2004-07-26 Thread Burhan Khalid
Albert Padley wrote:
I have been struggling with a javascript regex validation for U.S. phone 
This is a PHP list.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regex (Phone Number)

2004-07-26 Thread Curt Zirzow
* Thus wrote Albert Padley:
 I have been struggling with a javascript regex validation for U.S. 
 phone numbers all afternoon. This is part of Manuel Lemos' Formsgen 
 class. This is limited to the 7 digit number sans 3 digit area code. To 
 be complete, the regex should disallow a phone number that begins with 
 0 or 1, 555 or any digit followed by 11. Here is the regex I'm using:
 
 ^(?!\d[1]{2}|[5]{3})([2-9]\d{2})([-])\d{4}$

start yourself in a controlled environment, instead of trying to
comeup with the endless ways a number can be formated and remove
all non digits, then simply test the condistion of the string

  if substr(0,1) == 0 || substr(0,1) == 1
fail
  if substr(0,3) == 555
fail
  if substr(1,2) == 11
fail
  if strlen != 7
fail




Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Regex (Phone Number)

2004-07-25 Thread Albert Padley
I have been struggling with a javascript regex validation for U.S. 
phone numbers all afternoon. This is part of Manuel Lemos' Formsgen 
class. This is limited to the 7 digit number sans 3 digit area code. To 
be complete, the regex should disallow a phone number that begins with 
0 or 1, 555 or any digit followed by 11. Here is the regex I'm using:

^(?!\d[1]{2}|[5]{3})([2-9]\d{2})([-])\d{4}$
Manual Lemos indicated to me in an offline post that this should throw 
a javascript runtime error because of the (? at the beginning of the 
regex. I have tested it in over a dozen different browsers (Windows and 
Mac) and the only one that throws the runtime error is IE on the Mac. 
All others catch the errors I am trying to trap for with no runtime 
errors. Can this regex be improved on or do I have to live with the 
idiosyncratic behavior of Mac IE?

Thanks.
Albert Padley