首页 > 其他 > 详细

大陆港澳台身份证正则验证

时间:2021-05-29 13:17:52      阅读:20      评论:0      收藏:0      [点我收藏+]
public static boolean getisIdCard(String str) {

        //1.大陆 18 位   可含X
        String Dalu = "([1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx])|([1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3})";
        Pattern p = Pattern.compile(Dalu);
        Matcher m = p.matcher(str);
        boolean matches = m.matches();

        //香港8位  例:  X354670(A)      
        String hongKong = "[A-Za-z]{1}\\d{6}[(\\d)|A]{3}";
        Pattern p2 = Pattern.compile(hongKong);
        Matcher m2 = p2.matcher(str);
        boolean matches2 = m2.matches();

        //台湾10位 例: U193683453  
        String taiWan ="[A-Z]{1}\\d{9}";
        Pattern p3 = Pattern.compile(taiWan);
        Matcher m3 = p3.matcher(str);
        boolean matches3 = m3.matches();


        //澳门8位 例:5686611(1)  
        String maCao = "[1|5|7]\\d{6}[(\\d)]{3}";
        Pattern p1 = Pattern.compile(maCao);
        Matcher m1 = p1.matcher(str);
        boolean matches1 = m1.matches();

        if(matches||matches1||matches2||matches3){
            return true;
        }


        return false;
    }

  

大陆港澳台身份证正则验证

原文:https://www.cnblogs.com/tc310/p/14824866.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!