1.验证身份证
public static boolean checkIdentityCard(String identity_card){
String pattern = "((11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|50|51|52|53|54|61|62|63|64|65|71|81|82|91)\\d{4})((((19|20)(([02468][048])|([13579][26]))0229))|((20[0-9][0-9])|(19[0-9][0-9]))((((0[1-9])|(1[0-2]))((0[1-9])|(1\\d)|(2[0-8])))|((((0[1,3-9])|(1[0-2]))(29|30))|(((0[13578])|(1[02]))31))))((\\d{3}(x|X))|(\\d{4}))";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(identity_card);
return m.matches();
}
2.验证ip地址是否同一个段
/**
* 验证两个ip是否是同一个段
* @param ipStr
* @return
*/
public boolean checkIp(String ipStr){
Pattern pattern = Pattern.compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b");
//String ipStr="192.168.1.12/192.168.1.12";
String[] str=ipStr.split("/");
if(str.length==2){
Matcher matcher = pattern.matcher(str[0]);
Matcher matcher1 = pattern.matcher(str[1]);
if(matcher.matches()==true&&matcher1.matches()==true){//验证合法
int i=str[0].lastIndexOf(".");//得到最后一个.在字符串的那个位置
String ip0_1=str[0].substring(0,i);//前三段
int ip0_4=Integer.valueOf(str[0].substring(i+1, str[0].length()));
//System.out.println(ip0_1+"======"+ip0_4);
int j=str[1].lastIndexOf(".");
String ip1_1=str[1].substring(0,i);
int ip1_4=Integer.valueOf(str[1].substring(i+1, str[1].length()));
//System.out.println(ip1_1+"======"+ip1_4);
if(ip0_1.equals(ip1_1)&&ip0_4<=ip1_4){
return true;
}
}
}
return false;
}