Home Backend Development PHP Tutorial PHP mobile phone number verification judgment function_PHP tutorial

PHP mobile phone number verification judgment function_PHP tutorial

Jul 13, 2016 pm 05:14 PM
php function judgment Can phone number have friend regular use of expression verify

The simplest and most practical PHP mobile phone number regular expression, friends in need can refer to it.

Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 157(TD), 158, 159, 187, 188

China Unicom: 130, 131, 132, 152, 155, 156, 185, 186

Telecom: 133, 153, 180, 189, (1349 Satcom)

Mobile phone number rules

The code is as follows
 代码如下 复制代码

$regex = "/13[0-9]{9}|15[0|1|2|3|5|6|7|8|9]d{8}|18[0|5|6|7|8|9]d{8}/";

Copy code

$regex = "/13[0-9]{9}|15[0|1|2|3|5|6|7|8|9]d{8}|18[0|5|6 |7|8|9]d{8}/";

 代码如下 复制代码

function is_mobile($str){
return preg_match(“/^(((d{3}))|(d{3}-))?13d{9}$/“, $str);
}

 代码如下 复制代码


<?php
function checkMobile($str)
{
$pattern = “/^(13|15)d{9}$/”;
if (preg_match($pattern,$str))
{
Return true;
}
else
{
Return false;
}
}
//调用函数
$str = checkMobile(“15800000001″);
if($str)
{
echo(“符合手机号码标准”);
}
else
{
echo(“不符合手机号码标准”);
}
?>

Example 1


Judge mobile phone number:

function is_mobile($str){ return preg_match(“/^(((d{3}))|(d{3}-))?13d{9}$/“, $str);
The code is as follows
 代码如下 复制代码

preg_match_all($regex,$row['mobile'], $phones);
if($phones){
    正确
}

Copy code

}

Example
The code is as follows Copy code
<?php function checkMobile($str) { $pattern = “/^(13|15)d{9}$/”; If (preg_match($pattern,$str)) {

          Return true; }  
       else
{ <🎜>           Return false; <🎜> }  <🎜> } <🎜> //Call function <🎜> $str = checkMobile(“15800000001″); <🎜> if($str) <🎜> { <🎜> echo("Conforms to mobile phone number standards"); <🎜> } <🎜> else <🎜> { <🎜> echo("Does not meet mobile phone number standards"); <🎜> } <🎜> ?> Finally, you can completely verify all current mobile phone number codes
The code is as follows Copy code
preg_match_all($regex,$row['mobile'], $phones); if($phones){ Correct } Friendly reminder, it is really not easy to judge the mobile phone number now, because the mobile phone number has changed a lot. Maybe you wrote the regular rule today and a new number segment will be released tomorrow. Make a mobile phone number segment. For arrays, determine whether it is within the number segment. Array=array(130,131,132...)in_array(substr(number,0,3),array) http://www.bkjia.com/PHPjc/628966.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628966.htmlTechArticleThe simplest and most practical PHP mobile phone number regular expression, friends in need can refer to it. Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 157(TD), 158, 159, 187, 18...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles