четвъртък, 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();
}

1 коментар:

demosten каза...

This could also be done using
InetAddress.getByName(String host)