Here you can find the source of isIPv4Format(String str)
public static boolean isIPv4Format(String str)
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean isIPv4Format(String str) { Pattern p = Pattern.compile( "[1-2]{0,1}[0-9]{1,2}\\.[1-2]{0,1}[0-9]{1,2}\\.[1-2]{0,1}[0-9]{1,2}\\.[1-2]{0,1}[0-9]{1,2}"); Matcher m = p.matcher(str); if (m.matches()) { String[] strs = str.split("\\."); for (String str1 : strs) { if (Integer.valueOf(str1).intValue() > 255) { return false; }/*from w w w .j av a2s. c o m*/ } return true; } return false; } }