Here you can find the source of isIpAddress(String str)
public static boolean isIpAddress(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 IPADDRESS_PATTERN = "((?:(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))\\.){3}(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d))))"; public static boolean isIpAddress(String str) { return isMatcher(str, IPADDRESS_PATTERN); }// w w w .j av a2 s .c o m public static boolean isMatcher(String str, String pattern) { if (str == null) { return false; } if (pattern == null) { throw new IllegalArgumentException(); } Pattern pt = Pattern.compile(pattern); Matcher mc = pt.matcher(str); return mc.matches(); } }