本文主要介绍了PHP根据手机号判断运营商,详细介绍附代码,大家可以根据最新的号段进行添加即可,通过正则判断实现,需要的朋友可以参考下,希望能帮助到大家。
道理很简单,知道手机号规则 进行正则判断就可以
移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
联通:130、131、132、152、155、156、185、186
电信:133、153、180、189、(1349卫通)
HTML页面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <!DOCTYPE html>
<html lang= "en" >
<head>
<title>手机号归属</title>
</head>
<body>
<input type= "text" onblur= "mobile_check($(this).val())" >
</body>
</html>
<script type= "text/javascript" src= "__ROOT__/Public/admin/lib/jquery/1.9.1/jquery.min.js" ></script>
<script>
var phone = '';
function mobile_check(phone){
if (phone.length !== 11){
alert('未检测到正确的手机号码');
return false;
}
$.ajax({
url: "__CONTROLLER__/phone_check" ,
async:false,
dataType:'json',
type:'post',
data:{phone:phone},
success: function (msg){
alert(msg);
}
});
}
</script>
|
Copier après la connexion
controller控制代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public function phone_check(){
if (IS_POST){
$phone = I('phone');
$isChinaMobile = "/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|178|18[2-478])\d{8}$/" ;
$isChinaUnion = "/^(?:13[0-2]|145|15[56]|176|18[56])\d{8}$/" ;
$isChinaTelcom = "/^(?:133|153|177|173|18[019])\d{8}$/" ;
if (preg_match( $isChinaMobile , $phone )){
$this ->ajaxReturn('中国移动');
} else if (preg_match( $isChinaUnion , $phone )){
$this ->ajaxReturn('中国联通');
} else if (preg_match( $isChinaTelcom , $phone )){
$this ->ajaxReturn('中国电信');
} else {
$this ->ajaxReturn('未知');
}
}
$this ->display();
}
|
Copier après la connexion
相关推荐:
如何根据ip获得运营商的信息
JavaScript判断手机号运营商是移动、联通、电信还是其他(代码简单)_javascript技巧
js判断手机号运营商的方法_javascript技巧
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!