/**
* 检验是否是合法的IP地址
* @param address String IP地址
* @return boolean IP地址是否合法
*/
public static boolean isIpAddress(String address){
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)$";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(address);
return m.matches();
} |