Php's simplest mobile phone number verification program

Source: Internet
Author: User
Tags regular expression

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 );
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.