Re: Regex for telephone numbers

From: Date: Fri, 31 Dec 2010 15:53:24 +0000
Subject: Re: Regex for telephone numbers
References: 1  Groups: php.db php.general 
Request: Send a blank email to php-general+get-310427@lists.php.net to get a copy of this message
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. $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");
    }


« previous php.general (#310427) next »