Here you can find the source of isIpValid(String ip)
Parameter | Description |
---|---|
ip | a parameter |
public static boolean isIpValid(String ip)
//package com.java2s; //License from project: LGPL import java.util.regex.Pattern; public class Main { /**/*from w w w .j ava2 s.c o m*/ * IP address pattern */ private static final Pattern IP_PATTERN = Pattern .compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"); /** * * @param ip * @return true if the given string is a valid IP address */ public static boolean isIpValid(String ip) { return "localhost".equals(ip) || IP_PATTERN.matcher(ip).matches(); } }