RE: [PHP] regular expressions and Phone validation

From: Date: Wed, 15 Mar 2006 19:50:39 +0000
Subject: RE: [PHP] regular expressions and Phone validation
Groups: php.general 
Request: Send a blank email to php-general+get-231971@lists.php.net to get a copy of this message
[snip] 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? [/snip] There are several methods of doing phone number validation, one was even mentioned last week. You may try the archives for answers. What are you trying to do here? Once we know that we can probably help you.

« previous php.general (#231971) next »