Re: [PHP] Re: Regex for telephone numbers

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

On 12/31/2010 11:10 AM, ash@xxxxxxxxxxxxxxxxxxxx wrote:
Erm, you say regex is overkill, then use one in your example!


----- Reply message -----
From: "Al"<news@xxxxxxxxxxxxx>
Date: Fri, Dec 31, 2010 15:53
Subject: [PHP] Re: Regex for telephone numbers

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.



MySQL 5.1 PHP 5 Linux [Debian (sid)]

Regex is over-kill.

$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");

Save and use the resultant $phoneNum; It is all that needs to be saved and used. Dashes, spaces and () are superfluous. Only the 10 digits are required for his application.

PHP Database Mailing List (
To unsubscribe, visit:

[PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Plagiarism Notes]     [Postgresql]     [Yosemite News]

Powered by Linux