public static boolean isValidIPAddress(String str) { String temp =
"";
int tag =
0;
if (str.charAt(
0) ==
'.' || str.charAt(str.length() -
1) ==
'.')
return false;
for (
int i =
0; i < str.length(); i++) { System.out.println(
"temp ==="+temp);
if (str.charAt(i) ==
'.') { System.out.println(
"tag1 === "+tag); tag++; System.out.println(
"tag2 === "+tag);
if (Integer.parseInt(temp) >
255)
return false; temp =
"";
continue; }
if (str.charAt(i) <
'0' || str.charAt(i) >
'9')
return false; temp += String.valueOf(str.charAt(i)); } System.out.println(
"tag3 =="+tag);
if (tag !=
3)
return false;
return true; }
/**
* 判断ip地址的合法性
*/
public static boolean isValidIPAddress(String str) {
String temp = "";
int tag = 0;
//字符串的第一位和最后以为如果是.的话返回false
if (str.charAt(0) == '.' || str.charAt(str.length() - 1) == '.')
return false;
for (int i = 0; i < str.length(); i++) {
System.out.println("temp ==="+temp);
if (str.charAt(i) == '.') {
System.out.println("tag1 === "+tag);
tag++;
System.out.println("tag2 === "+tag);
if (Integer.parseInt(temp) > 255)
return false;
temp = "";
continue;
}
if (str.charAt(i) < '0' || str.charAt(i) > '9')
return false;
temp += String.valueOf(str.charAt(i));
}
System.out.println("tag3 =="+tag);
if (tag != 3)
return false;
return true;
}