public static boolean IPisCorrect(String ip) {
Pattern p = Pattern
.compile("^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$");
Matcher m = p.matcher(ip);
boolean b = m.matches();
return b;
}
本文介绍了一个用于验证IPv4地址格式正确性的Java方法。通过正则表达式匹配来判断输入的字符串是否符合标准IPv4地址的格式规范。
9254

被折叠的 条评论
为什么被折叠?



