Simplest verification of mobile phone numbers
All Chinese mobile phones start with 1 and contain 10 digits.
Use regular expression ^ 1 ([0-9] {9 })
The code is as follows: |
Copy code |
<? Php $ Mobile = '000000 '; If (! Preg_match ('/^ 1 ([0-9] {9})/', $ mobile) exit ('mobile phone error '); ?>
|
^ The first character of 1 is 1 and is not interpreted
[0-9] numbers from zero to nine
{9} repeat 10 times, that is, 1 plus nine digits
The above is not a mobile phone number, but it can also be difficult. For example, 19999999999, but this is not a mobile phone number.
We can find
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)
Example 2
The code is as follows: |
Copy code |
Function is_mobile ($ str ){ Return preg_match ("/^ (d {3}) | (d {3 }-))? 13d {9 }$/", $ str ); } |