import java.util.regex.Pattern;\r
\r
public class IPValidator {\r
- private static final Pattern ipv4_p = Pattern.compile(\r
- "^((\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}\\2$"\r
- );\r
+ private static final Pattern ipv4_p = Pattern.compile(\r
+ "^((\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}\\2$"\r
+ );\r
\r
- private static final Pattern ipv6_p = Pattern.compile(\r
- "^(([0-9a-fA-F]{0,4})([:|.])){2,7}([0-9a-fA-F]{0,4})$"\r
- );\r
- \r
- private static final Pattern doubleColon = Pattern.compile(\r
- ".*::.*::.*"\r
- );\r
+ private static final Pattern ipv6_p = Pattern.compile(\r
+ "^(([0-9a-fA-F]{0,4})([:|.])){2,7}([0-9a-fA-F]{0,4})$"\r
+ );\r
+ \r
+ private static final Pattern doubleColon = Pattern.compile(\r
+ ".*::.*::.*"\r
+ );\r
\r
- private static final Pattern tooManyColon = Pattern.compile(\r
- "(.*:){1,7}"\r
- );\r
+ private static final Pattern tooManyColon = Pattern.compile(\r
+ "(.*:){1,7}"\r
+ );\r
\r
- \r
- public static boolean ipv4(String str) {\r
- return ipv4_p.matcher(str).matches();\r
- }\r
- \r
- public static boolean ipv6(String str) {\r
- return ipv6_p.matcher(str).matches() &&\r
- !doubleColon.matcher(str).matches() &&\r
- !tooManyColon.matcher(str).matches();\r
- }\r
- \r
- public static boolean ip (String str) {\r
- return ipv4_p.matcher(str).matches() || ipv6(str);\r
- }\r
+ \r
+ public static boolean ipv4(String str) {\r
+ return ipv4_p.matcher(str).matches();\r
+ }\r
+ \r
+ public static boolean ipv6(String str) {\r
+ return ipv6_p.matcher(str).matches() &&\r
+ !doubleColon.matcher(str).matches() &&\r
+ !tooManyColon.matcher(str).matches();\r
+ }\r
+ \r
+ public static boolean ip (String str) {\r
+ return ipv4_p.matcher(str).matches() || ipv6(str);\r
+ }\r
}\r