PHP judges the operator according to the mobile phone number. of introduces the attached code in detail
- 2021-08-31 07:23:10
- OfStack
The reason is very simple. You can know the rules of mobile phone number and make regular judgments
Movement: 134, 135, 136, 137, 138, 139, 150, 151, 157 (TD), 158, 159, 187, 188
Unicom: 130, 131, 132, 152, 155, 156, 185, 186
Telecommunications: 133,153,180, 189, (1349 Satcom)
HTML page
<!DOCTYPE html>
<html lang="en">
<head>
<title> Mobile phone number attribution </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> // Modify to your own path
<script>
/*
Move: 134 , 135 , 136 , 137 , 138 , 139 , 150 , 151 , 157(TD) , 158 , 159 , 187 , 188
Unicom: 130 , 131 , 132 , 152 , 155 , 156 , 185 , 186
Telecommunications: 133 , 153 , 180 , 189 , ( 1349 Satcom)
*/
var phone = '';
function mobile_check(phone){
if(phone.length !== 11){
alert(' The correct mobile phone number was not detected ');
return false;
}
$.ajax({
url:"__CONTROLLER__/phone_check",
async:false,
dataType:'json',
type:'post',
data:{phone:phone},
success:function(msg){
alert(msg);
}
});
}
</script>
controller control code
/*
*@param string $phone Cell phone number string
*@return 0 China Mobile, 1 China Unicom 2 China Telecom 3 Unknown
*/
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}$/"; // Latest reply on mobile
$isChinaUnion = "/^(?:13[0-2]|145|15[56]|176|18[56])\d{8}$/"; // Confirm to Unicom Weibo that there is no reply
$isChinaTelcom = "/^(?:133|153|177|173|18[019])\d{8}$/"; //1349 Segment number Telecommunications did not give a reply and was regarded as nonexistent
// $isOtherTelphone = "/^170([059])\\d{7}$/";// Other operators
if(preg_match($isChinaMobile, $phone)){
$this->ajaxReturn(' China Mobile '); //0
}else if(preg_match($isChinaUnion, $phone)){
$this->ajaxReturn(' China Unicom '); //1
}else if(preg_match($isChinaTelcom, $phone)){
$this->ajaxReturn(' China Telecom '); //2
}else{
$this->ajaxReturn(' Unknown '); //3
}
}
$this->display();
}
The above is all the implementation code, and friends who need it can refer to 1