/**
* 验证手机号或座机号的合法性
* @param unknown $str
* @param string $flag 默认验证手机号的合法性
* @return boolean
*/
function checkMobile($str, $flag = 'mobile')
{
$match_mobile = '/1[34578]{1}\d{9}$/';
$match_phone = '/^(0?(([1-9]\d)|([3-9]\d{2}))-?)?\d{7,8}$/';
switch ($flag) {
case 'mobile': //手机
return (preg_match($match_mobile, $str)) ? true : false;
break;
case 'phone': //座机
return (preg_match($match_phone, $str)) ? true : false;
break;
default:
return (preg_match($match_mobile, $str)) || (preg_match($match_phone, $str));
break;
}
}