Android 校验手机号——正则表达式


1、粗略匹配手机号的正则:

第1位:1
第2位:3-9 任意数字
其他位:任意数字

//正则表达式
^1[3456789][0-9]{
    
    9}&
2、精准匹配手机号的正则:

第1位:1
第2、3位:3[0-9]、4[57]、5[012356789]、66、7[013678]、8[0-9]、9[89]
其他位:任意数字

//正则表达式
^(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57]|19[89]|166)[0-9]{
    
    8}&
3、校验手机号的方法
public class MobileUtils {
    
    
 
    //校验通过返回true,否则返回false
    public static boolean isMobile(String mobile) {
    
    
 
        String str = mobile;
        String pattern = "^(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57]|19[89]|166)[0-9]{8}";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(str);
 
        return m.matches();
    }
}

猜你喜欢

转载自blog.csdn.net/fenglolo/article/details/126266689