Home  >  Article  >  Backend Development  >  PHP validate mobile phone number with regular expression

PHP validate mobile phone number with regular expression

coldplay.xixi
coldplay.xixiforward
2020-06-11 09:05:229226browse

PHP validate mobile phone number with regular expression

PHP regular expression to verify mobile phone number

Regular expression to verify whether it is a mobile phone number

Code:

/**
 * 验证输入的手机号码
 * @access  public
 * @param   string      $user_mobile      需要验证的手机号码
 * @return bool
 */
function is_mobile($user_mobile){
    $chars = "/^((\(\d{2,3}\))|(\d{3}\-))?1(3|5|8|9)\d{9}$/";
    if (preg_match($chars, $user_mobile)){
        return true;
    }else{
        return false;
    }
}

At present, almost every system requires the use of a mobile phone. Whether it is to log in as a user name or to bind a mobile phone number for verification, etc., the mobile phone number is required as the only identification. In order to identify whether the user is Enter it at will. At this time, we need to use PHP to verify whether it is the correct mobile phone number format. The above is my custom regular expression for verifying the mobile phone number. You can refer to it for improvement.

Recommended tutorial: "PHP Video Tutorial"

The above is the detailed content of PHP validate mobile phone number with regular expression. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:liqingbo.cn. If there is any infringement, please contact admin@php.cn delete