Java IP Address Validate isIPv4Format(String str)

Here you can find the source of isIPv4Format(String str)

Description

is I Pv Format

License

Open Source License

Declaration

public static boolean isIPv4Format(String str) 

Method Source Code

//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;
    }
}

Related

  1. isIPv4Address(final String input)
  2. isIPv4Address(String ipAddress)
  3. isIPv4AddressValid(String cidr)
  4. isIpv4Correct(String ipAddress)
  5. isIPv4Format(String ip)
  6. isIPv4LiteralAddress(String src)
  7. isIPv4LiteralAddress(String string)
  8. isIpV4PortAddress(String s)
  9. isIpV4StrValid(String str)