RE: Phone number validation

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

 



 
I do this for phone numbers:

$row['mobile'] = ereg_replace("[^0-9]", '', $_POST['mobile']);


if ((strlen($phone)) <= 14) 
	return preg_replace
("/[^0-9]*([0-9]{3})[^0-9]*([0-9]{3})[^0-9]*([0-9]{4}).*/", "(\\1) \\2-\\3",
$phone);

> Is it possible for anyone to tell me what php method is used to grab
> the first charater of a string?  And once I have it what method
> removes the characted or number?

$foo = 'this is a string';

$foo[0] == 't';


> -----Original Message-----
> From: tedd [mailto:tedd@xxxxxxxxxxxx] 
> Sent: Sunday, March 12, 2006 2:20 PM
> To: php-general@xxxxxxxxxxxxx; Paul Goepfert
> Subject: Re:  Phone number validation
> 
> Paul:
> 
> Also check out:
> 
> http://www.weberdev.com/get_example-3605.html
> 
> tedd
> 
> 
> >Hi all,
> >
> >I am trying to validate phone numbers in a web form that I have
> >created.  I am using a regular expression to validate the phone
> >number.  It seems when I enter the phone number in the following ways
> >I get errors
> >
> >(123) 456 7890
> >123 456 7890
> >(123) 456 - 7890
> >123 456-7890
> >
> >I am using the ereg method in php to test the regular expression.
> >Here is the Regular Expression that I am using to test against
> >potential phone numbers
> >
> >$validPhone = "^([0-9]{3}[ ]*)?[0-9]{3}[ ]*[0-9]{4}$";
> >
> >By the way The phone numbers are in US format.
> >
> >If anyone can help me with this I would really appreciate it.

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