PHP根据手机号判断运营商(详细介绍附代码)
网络编程 2021-07-05 08:24www.168986.cn编程入门
这篇文章主要介绍了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页面
<!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> /* 移动: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卫通) */ 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}, suess:function(msg){ alert(msg); } }); } </script>
controller控制代码
/* *@param string $phone 手机号字符串 *@return 0中国移动,1中国联通 2中国电信 3未知 */ 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}$/"; //向联通微博确认并未回复 $isChinaTel = "/^(?:133|153|177|173|18[019])\d{8}$/"; //1349号段 电信方面没给出答复,视作不存在 // $isOtherTelphone = "/^170([059])\\d{7}$/";//其他运营商 if(preg_match($isChinaMobile, $phone)){ $this->ajaxReturn('中国移动'); //0 }else if(preg_match($isChinaUnion, $phone)){ $this->ajaxReturn('中国联通'); //1 }else if(preg_match($isChinaTel, $phone)){ $this->ajaxReturn('中国电信'); //2 }else{ $this->ajaxReturn('未知'); //3 } } $this->display(); }
以上就是全部的实现代码了,需要的朋友可以参考一下
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程