0
点赞
收藏
分享

微信扫一扫

Java 判断Ip的正则表达

  1. IP v4 校验

public static boolean isboolIp(String ipAddress) {
String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
Pattern pattern = Pattern.compile(ip);
Matcher matcher = pattern.matcher(ipAddress);
return matcher.matches();
}

2.IP v6 校验

public static void isboolIpv6(String ipAddress) {    
String re = "^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$";
return ipAddress.matches(re);
}

举报

相关推荐

0 条评论