[PHP] Re: Regex for telephone numbers

2010-12-31 Thread Al



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-.

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

}

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



Re: [PHP] Re: Regex for telephone numbers

2010-12-31 Thread a...@ashleysheridan.co.uk
Erm, you say regex is overkill, then use one in your example!

Thanks,
Ash
http://www.ashleysheridan.co.uk

- Reply message -
From: Al n...@ridersite.org
Date: Fri, Dec 31, 2010 15:53
Subject: [PHP] Re: Regex for telephone numbers
To: php...@lists.php.net, php-general@lists.php.net



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-.

 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);
 }

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



Re: [PHP] Re: Regex for telephone numbers

2010-12-31 Thread Al



On 12/31/2010 11:10 AM, a...@ashleysheridan.co.uk wrote:

Erm, you say regex is overkill, then use one in your example!

Thanks,
Ash
http://www.ashleysheridan.co.uk

- Reply message -
From: Aln...@ridersite.org
Date: Fri, Dec 31, 2010 15:53
Subject: [PHP] Re: Regex for telephone numbers
To:php...@lists.php.net,php-general@lists.php.net



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-.

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);
  }



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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Regex for telephone numbers

2010-12-31 Thread Per Jessen
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-.

 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