Could someone help me with verifying phone numbers like (415) 765-6890. It consists of 3 numerals in round brackets, then a space, then 3 numerals again, then a minus sign, then 4 numerals.
Please help me.
| SitePoint Sponsor |

Could someone help me with verifying phone numbers like (415) 765-6890. It consists of 3 numerals in round brackets, then a space, then 3 numerals again, then a minus sign, then 4 numerals.
Please help me.




Code:/^\(\d{3}\) \d{3}\-\d{4}$/

It is NOT working:
.Code:$pattern = "/^\(\d{3}\) \d{3}\-\d{4}$/"; $subject = "(415) 956-2003"; if( ereg($pattern, $subject) ) echo "CORRECT"; else echo "WRONG";




Who told you to use ereg?
PHP Code:$pattern = "/^\(\d{3}\) \d{3}\-\d{4}$/";
$subject = "(415) 956-2003";
if (preg_match($pattern, $subject))
echo "CORRECT";
else
echo "WRONG";

Fine. You're regex expert!
Bookmarks