/** * 检验是否是合法的IP地址 * @param address String IP地址 * @return boolean IP地址是否合法 */ public static boolean isIpAddress(String address){ String regex = "(((2[0-4]d)|(25[0-5]))|(1d{2})|([1-9]d)|(d))[.](((2[0-4]d)|(25[0-5]))|(1d{2})|([1-9]d)|(d))[.]" + "(((2[0-4]d)|(25[0-5]))|(1d{2})|([1-9]d)|(d))[.](((2[0-4]d)|(25[0-5]))|(1d{2})|([1-9]d)|(d))"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(address); return m.matches(); } //源代码片段来自云代码http://yuncode.net