PHP Verification Mobile Phone number, verify mobile phone number
Everyone should have this common sense, China's mobile phone numbers are based on the number "1" Start, and then use "0~9" 10 numbers composed of 11-digit combination, then our validation rules must be based on this idea to write.
Based on the simple idea above, we can write down the following verification code, the code is as follows:
<?php// This code is only to provide some ideas //distance actual application also some distance $mobile = ' 15858588585 '; The following 1 is the first digit of the cell phone must be the number 1//[0-9] refers to the number after the number is 0~9 //{9} The middle of the 9 refers to the mobile phone number in addition to the first digit, the other to repeat 10 times, just 11 digits of the if (!preg_ Match ('/^1 ([0-9]{9}]/', $mobile) ' Exit (' Your mobile phone number is incorrect ');
But the above code is obviously not rigorous enough, because this way, even if the "18888888888" mobile phone number can be verified, so we have to be more rigorous verification, before strict please let us first look at China's common mobile phone number of the top three have those:
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 change the code into such a rule, the code is as follows:
<?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 ("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:
function Is_mobile ($str) { return Preg_match ("/^ ((D{3}) | ( d{3}-)) 13d{9}$/", $str);
This will be able to verify all the mobile phone number, the entire analytic thinking closely linked to PHP verification mobile phone number for detailed analysis, to obtain a solution.
The above is for everyone to share the method of PHP verification mobile phone number, I hope that everyone's learning has helped.
http://www.bkjia.com/PHPjc/1070270.html www.bkjia.com true http://www.bkjia.com/PHPjc/1070270.html techarticle PHP Verification Mobile phone number, verify the mobile phone number everyone should have this common sense, China's mobile phone number is the number "1" Start, and then use "0~9" 10 numbers of 11-digit combination of numbers ...