Home >Backend Development >PHP Tutorial >PHP verifies whether the entered mobile phone number is legal

PHP verifies whether the entered mobile phone number is legal

小云云
小云云Original
2018-03-09 11:49:585619browse

This article mainly shares with you the example code of PHP verifying whether the entered mobile phone number is legal. I hope it can help everyone.

function is_mobile_phone ($mobile_phone)
{
    
    $chars = "/^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$|17[0-9]{1}[0-9]{8}$/";
    if(preg_match($chars, $mobile_phone))
    {
        return true;
    }
    
    return false;
}

Related recommendations:

AngularJS implements form verification mobile phone number function

How jQuery uses regular expressions to verify mobile phone numbers and ID cards Number, Chinese name

javascript - Problem with regular verification of mobile phone number

The above is the detailed content of PHP verifies whether the entered mobile phone number is legal. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn