Re: excluding parenthesis, space and dashes from phone number

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

 



I suck at regex.. but found this a while ago.   Supposedly it'll strip all 
non-numeric characters, so I've used it for phone #'s and SSNs:

preg_replace ('/[^\d]+/s', '', $var)

-TG

----- Original Message -----
From: afan pasalic <afan@xxxxxxxx>
To: php-general <php-general@xxxxxxxxxxxxx>
Date: Fri, 30 Nov 2007 08:44:38 -0500
Subject:  excluding parenthesis, space and dashes from phone number

> hi,
> I store phone number in mysql as integer, e.g. (123) 456-7890 is stored
> as 1234567890.
> though, in search form they usually type in a phone number with
> parenthesis/space/dashes. I have to extract numbers before I search
> through mysql.
> 
> currently, I use eregi_replace() function, several times, to do the job:
> eregi_replace(' ', '', $phone);
> eregi_replace('(', '', $phone);
> eregi_replace(')', '', $phone);
> eregi_replace('-', '', $phone);
> and it works fine.
> 
> but, is there any better way? more "fancy"? :)
> 
> thanks for any help.
> 
> -afan
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

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