java backstage regular expression to validate a variety of methods - (Hong Kong and Macao document verification)

In the first browser console can measure what you have written a regular expression is correct:

/**
     * 是否是港澳证件号
     * 
     * @param str
     * @return
     */
    public  static boolean isIdCard3(String str) {       
    	if(str==null){
    			return false;
		  }else{
		  	String re = "^[HMhm]{1}([0-9]{10}|[0-9]{8})$";
		      Pattern p = Pattern.compile(re);
		      Matcher m = p.matcher(str);
		      boolean d = m.matches();
		      System.out.println(d); 
		      return d;
		  }
    } 
    public static boolean isIdCard2(String str) {

    	if (null == str || "".equals(str)) return false;
        String regex = "^[HMhm]{1}([0-9]{10}|[0-9]{8})$";
        System.out.println(str.matches(regex));
        return str.matches(regex);
        
    }
    public  static boolean isIdCard(String str) {       
        String regex = "^[HMhm]{1}([0-9]{10}|[0-9]{8})$"; 
        boolean flg = Pattern.matches(regex, str); 
        System.out.println(flg); 
        return flg; 
    }

 

Published 141 original articles · won praise 33 · views 50000 +

Guess you like

Origin blog.csdn.net/qq_43560721/article/details/101768750