Here you can find the source of isIpAddress(String addr)
public static boolean isIpAddress(String addr)
//package com.java2s; //License from project: Apache License import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean isIpAddress(String addr) { if (addr.length() < 7 || addr.length() > 15 || "".equals(addr)) { return false; }//w ww . ja v a2 s . c o m 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); boolean ipAddress = mat.find(); return ipAddress; } }