regular expressions and Phone validation
| From: | Paul Goepfert | Date: | Wed, 15 Mar 2006 19:28:01 +0000 |
| Subject: | regular expressions and Phone validation | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-231968@lists.php.net to get a copy of this message | ||
Hi all,
I have one small problem I don't understand the preg_replace() method.
I understand the gist of what it does but I still don't fully know
what it does. I have read the entry in the php manual about this and
I am still confused about it. I've never been any good with regular
expressions.
Here is the function in use:
function checkPhone ($Phone)
{
global $errmsg;
if (!empty($Phone))
{
$Phone = ereg_replace("[^0-9]", '', $Phone);
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);
}
}
I think my problem is mostly what is returned when preg_replace executes?
Paul