четвъртък, 25 юни 2009 г.

Validate IP address in Java


public static boolean isValidIP(String ip) {
final Pattern IP_PATTERN = Pattern.compile("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).)" + "{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");
return IP_PATTERN.matcher(ip).matches();
}