Detect whether the mobile phone number is legal

Notice:

The regular expressions of the mobile phone numbers of the three operators are not static
The regular expressions of the mobile phone numbers of the three operators are not static
The regular expressions of the mobile phone numbers of the three operators are not static

Code example:

    ///检测手机号码是否合法
    private bool CheckPhoneIsAble(string input)
    {
    
    
        if (input.Length != 11)
        {
    
    
            return false;
        }
        
        // 电信手机号码正则(请根据情况改变此正则表达式)
        string dianxin = @"^1[3578][01379]\d{8}$";
        Regex regexDX = new Regex(dianxin);
        
        // 联通手机号码正则(请根据情况改变此正则表达式)
        string liantong = @"^1[34578][01256]\d{8}";
        Regex regexLT = new Regex(liantong);
        
        // 移动手机号码正则(请根据情况改变此正则表达式)
        string yidong = @"^(1[012345678]\d{8}|1[345678][012356789]\d{8})$";
        Regex regexYD = new Regex(yidong);
        
        if (regexDX.IsMatch(input) || regexLT.IsMatch(input) || regexYD.IsMatch(input))
        {
    
    
            return true;
        }
        else
        {
    
    
            return false;
        }
    }

Ending: If there is a problem, please correct me.

Guess you like

Origin blog.csdn.net/weixin_43830069/article/details/129747240