The simplest and most practical Regular Expression for php mobile phone numbers. For more information, see.
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
China Telecom: 133, 153, 180, 189 (1349 Weitong)
Mobile phone number rules
The Code is as follows: |
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 }/"; |
Example 1
Determine the mobile phone number:
The Code is as follows: |
Copy code |
Function is_mobile ($ str ){ Return preg_match ("/^ (d {3}) | (d {3 }-))? 13d {9 }$/", $ str ); } |
Instance
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 a function $ Str = checkMobile (15800000001 ″); If ($ str) { Echo ("compliant with mobile phone number standards "); } Else { Echo ("not compliant with mobile phone number Standards "); } ?>
|
Finally, all mobile phone numbers can be verified.
The Code is as follows: |
Copy code |
Preg_match_all ($ regex, $ row ['mobile'], $ phones ); If ($ phones ){ Correct } |
Friendly reminder: it is really difficult to judge the mobile phone number, because the mobile phone number has changed a lot. maybe you have written a regular expression today, and a new number segment will be generated tomorrow. Make a cell phone number segment array and determine whether the array is in the number segment = array (130,131,132 .....) in_array (substr (number, 0, 3), array)