Verify the mobile phone number we are using the PHP regular expression test verification, the mobile phone number of the rule is 11-bit length and then 13,15,18, and so on, we just need to classify the plan and to achieve the perfect mobile phone number verification regular.
Everyone should have this common sense, China's mobile phone numbers are the number "1" beginning, and then use "0~9" 10 numbers of 11-bit
Combination of numbers, then our validation rules must be written according to this idea.
Based on the simple idea above, we can write down the following verification code:
The code is as follows |
Copy Code |
This code is just to provide some ideas There are some distances from the actual application $mobile = ' 15858588585 '; The following 1 is the first digit of the phone must be the number 1 [0-9] refers to the number of the following numbers are 0~9 {9} The middle of 9 refers to the mobile phone number in addition to the first digit, the other to repeat 10 times, just 11 digits. if (!preg_match ('/^1 ([0-9]{9})/', $mobile)] Exit (' Your mobile phone number is incorrect '); ?> |
But the above code is clearly not rigorous, because this way, even if "18888888888" such a mobile phone number can be verified, because
We will also be more rigorous verification of it, before strict please let us first look at China's common mobile phone number The first three people have that
Some:
Mobile phone Number: 134, 135, 136, 137, 138, 139, 150, 151, 157 (TD), 158, 159, 187, 188
Unicom Mobile phone Number: 130, 131, 132, 152, 155, 156, 185, 186
Mobile phone Number: 133, 153, 180, 189, (1349 Wei Tong)
So according to the above features, we can modify the code to such a rule:
The code is as follows |
Copy Code |
function Checkmobile ($STR) { $pattern = "/^ (13|15) d{9}$/"; if (Preg_match ($pattern, $STR)) { Return true; } Else { Return false; } } Calling functions $str = Checkmobile ("15800000001″"); if ($STR) { Echo ("Compliant with mobile phone number standard"); } Else { Echo ("Does not conform to mobile phone number standard"); } ?> |
Above can only Zhui 13, 15, if there is a new paragraph is not, we can modify
The code is as follows |
Copy Code |
function Is_mobile ($STR) { Return Preg_match ("/^ ((D{3}) | ( d{3}-)) 13d{9}$/", $str); } |
This will allow you to verify all your mobile phone numbers.
http://www.bkjia.com/PHPjc/631504.html www.bkjia.com true http://www.bkjia.com/PHPjc/631504.html techarticle Verify the mobile phone number we are using the PHP regular expression test verification, the mobile phone number of the rule is 11-bit length and then 13,15,18, and so on, we just need to classify the planning and can achieve ...