Re: Re: Regex for telephone numbers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Al wrote:

> 
> 
> On 12/29/2010 7:12 PM, Ethan Rosenberg wrote:
>> Dear List -
>>
>> Thank you for all your help in the past.
>>
>> Here is another one....
>>
>> I would like to have a regex which would validate that a telephone
>> number is in the format xxx-xxx-xxxx.
>>
>> Thanks.
>>
>> Ethan
>>
>> MySQL 5.1 PHP 5 Linux [Debian (sid)]
>>
> 
> Regex is over-kill.

You've just used one any way:

> $phoneNum = preg_replace("%\D%", '', $phoneNum);//Remove everything except digits 
> 
> $phoneNum = ltrim($phoneNum,'1');//Remove leading 1s
> 
> if(strlen($phoneValue) != 10)
>      {
> throw new Exception("Phone number must be 10 digits, without leading a
> 1. Check your entry carefull");
>      }

One regex and two function calls when one regex would have sufficed?


-- 
Per Jessen, ZÃrich (2.6ÂC)


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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux