Here you can find the source of isIp(String str)
public static boolean isIp(String str)
//package com.java2s; //License from project: Open Source License import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final String REGEX_IP = "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b"; public static boolean isIp(String str) { return regex(str, REGEX_IP); }/*from w w w . ja v a2 s . c o m*/ public static final boolean regex(String testStr, String regStr) { Pattern p = Pattern.compile(regStr); Matcher m = p.matcher(testStr); return m.matches(); } }