Java后端开发——利用正则表达式判断手机号格式正误代码示例

public boolean isMobile(String str) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        String s2="^[1](([3|5|8][\\d])|([4][5,6,7,8,9])|([6][5,6])|([7][3,4,5,6,7,8])|([9][8,9]))[\\d]{8}$";// 验证手机号
        if(StringUtils.isNotBlank(str)){
            p = Pattern.compile(s2);
            m = p.matcher(str);
            b = m.matches();
        }
        return b;
}

 

扫码关注公众号,查看更多精彩内容

posted @ 2019-11-15 15:56  不是公子的小白  阅读(2306)  评论(0编辑  收藏  举报