RE: [PHP] Phone number validation
| From: | Daevid Vincent | Date: | Mon, 13 Mar 2006 06:21:29 +0000 |
| Subject: | RE: [PHP] Phone number validation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-231827@lists.php.net to get a copy of this message | ||
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@sperling.com]
> Sent: Sunday, March 12, 2006 2:20 PM
> To: php-general@lists.php.net; Paul Goepfert
> Subject: Re: [PHP] 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.