如何在php中使用正则表达式验证电话号码? [重复]

This question already has an answer here:

I'm coding in php and I would be happy if someone could help me with a regex that would validate phone numbers in the format +233 245 245 245 or 0245 245 245.

I would also want the phone number to be validated whether or not the spaces are included. Thanks a lot in advance.

</div>

Something simple like this would work:

$string = "(232) 555-5555";
$expr = '/^\+?(\(?[0-9]{3}\)?|[0-9]{3})[-\.\s]?[0-9]{3}[-\.\s]?[0-9]{4}$/';
if (preg_match($expr, $string) == 1)
{
echo "number validated successfully.";
}