The simplest and most practical regular expression for php mobile phone numbers. For more information, see Mobile: 134, 135, 136, 137, 138, China Unicom: 130, 131, 132, 152, China Telecom: 133, 153, 180, 189 ,,
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)
The instance code of the mobile phone number rule 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 }/";
The code used to determine the mobile phone number is as follows:
- Function is_mobile ($ str ){
- Return preg_match ("/^ (d {3}) | (d {3 }-))? 13d {9 }$/", $ str );
- }
The instance code is as follows:
-
- 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 instance code is as follows:
- 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)