PHP手机格式检查支持国际手机格式检查,函数实现方式摘抄自Thinkcmf框架
/**
* 检查手机格式,中国手机不带国家代码,国际手机号格式为:国家代码-手机号
* @param $mobile
* @return bool
*/
function cmf_check_mobile($mobile)
{
if (preg_match('/(^(13\d|14\d|15\d|16\d|17\d|18\d|19\d)\d{8})$/', $mobile)) {
return true;
} else {
if (preg_match('/^\d{1,4}-\d{5,11}$/', $mobile)) {
if (preg_match('/^\d{1,4}-0+/', $mobile)) {
//不能以0开头
return false;
}
return true;
}
return false;
}
}
相关文章