这是我从某个地方下载的函数(不记得我从哪里得到的)。
/*
// PHP function to validate US phone number:
// (c) 2003
// No restrictions have been placed on the use of this code
//
// Updated Friday Jan 9 2004 to optionally ignore the area code:
//
// Input: a single string parameter and an optional boolean variable (default=true)
// Output: 10 digit telephone number or boolean false(0)
//
// The function will return the numerical part of the alphanumeric string
// parameter with the following sequence of characters:
// any number of spaces [optional],
// a single open parentheses [optional],
// any number of spaces [optional],
// 3 digits (area code),
// any number of spaces [optional],
// a single close parentheses [optional],
// a single dash [optional],
// any number of spaces [optional],
// 3 digits, any number of spaces [optional],
// a single dash [optional],
// any number of spaces [optional],
// 4 digits, any number of spaces [optional]:
*/
function validate_USphone($phonenumber, $useareacode=true)
{
if ( preg_match("/^[ ]*[(]{0,1}[ ]*[0-9]{3,3}[ ]*[)]{0,1}[-]{0,1}[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/",$phonenumber) || (preg_match("/^[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/",$phonenumber) && !$useareacode)) return preg_replace("/[^0-9]/i", "", $phonenumber);
return false;
}