public static boolean IPCheck(String str) {
if (str != null && !str.isEmpty()) {
// 定義正則表達式
String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
// 判斷ip地址是否與正則表達式匹配
if (str.matches(regex)) {
// 返回判斷信息
return true;
} else {
// 返回判斷信息
return false;
}
}
return false;
}