Php mobile phone number verification judgment Function

Source: Internet
Author: User

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)

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.