PHP Mobile number verification Function _php Tutorial

Source: Internet
Author: User
The simplest of the most practical PHP mobile phone number Regular expression, there is a need for friends to refer to.

Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 157 (TD), 158, 159, 187, 188

Unicom: 130, 131, 132, 152, 155, 156, 185, 186

Telecom: 133, 153, 180, 189, (1349 Wei Tong)

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 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


function Checkmobile ($STR)
{
$pattern = "/^ (13|15) d{9}$/";
if (Preg_match ($pattern, $STR))
{
Return true;
}
Else
{
Return false;
}
}
Calling functions
$str = Checkmobile ("15800000001″");
if ($STR)
{
Echo ("Compliant with mobile phone number standard");
}
Else
{
Echo ("Does not conform to mobile phone number standard");
}
?>


Finally, you can fully verify the current phone number code

The code is as follows Copy Code

Preg_match_all ($regex, $row [' Mobile '], $phones);
if ($phones) {
That's right
}

Friendship tips, now about cell phone judgment, is really not very good to do, because the mobile phone number changes have been relatively large. Maybe today you write a regular, tomorrow will be a new number segment, make a cell phone number segment array, determine whether in the number segment array =array (130,131,132 ...) In_array (substr (number, 0, 3), array)

http://www.bkjia.com/PHPjc/628966.html www.bkjia.com true http://www.bkjia.com/PHPjc/628966.html techarticle The simplest of the most practical PHP mobile phone number Regular expression, there is a need for friends to refer to. Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 157 (TD), 158, 159, 187 , ...

  • 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.