Here you can find the source of isIp(String str)
public static boolean isIp(String str)
//package com.java2s; //License from project: Apache License import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean isIp(String str) { boolean result = validByRegex( "^(?:(?: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]?)$", str);//from ww w.j a v a 2s . co m return result; } public static boolean validByRegex(String regex, String str) { Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher regexMatcher = pattern.matcher(str); return regexMatcher.find(); } }