Android examples for java.net:IP Address
is Ip Address by regex
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ /**//from ww w.j a v a 2 s .co m * isIpAddress * whether a charSequence is a valid ip address. * @param addr * @return */ public static boolean isIpAddress(CharSequence addr) { if (addr == null) return false; if (addr.length() < 7 || addr.length() > 15 || "".equals(addr)) { return false; } String rexp = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}"; Pattern pat = Pattern.compile(rexp); Matcher mat = pat.matcher(addr); return mat.find(); } }