Java IP Address Validate isIpAddress(String str)

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

Description

is Ip Address

License

Open Source License

Declaration

public static boolean isIpAddress(String str) 

Method Source Code

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

Related

  1. isIPAddress(String ipAddress)
  2. isIpAddress(String ipAddress)
  3. isIpAddress(String ipAddress)
  4. isIPAddress(String ipAddress)
  5. isIPAddress(String line)
  6. isIPAndPort(String text)
  7. isIpFormat(String ip)
  8. isIPSect(String ip)
  9. isIPString(String str)