Java IP Address Validate isIp(Object obj)

Here you can find the source of isIp(Object obj)

Description

is Ip

License

Open Source License

Declaration

public static boolean isIp(Object obj) 

Method Source Code


//package com.java2s;
import java.util.regex.*;

public class Main {
    public static final String IP_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
            + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
            + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";

    public static boolean isIp(Object obj) {
        return matches(IP_PATTERN, obj);
    }//from   w  w w  .  j  av a  2s. co  m

    private static boolean matches(String pattern, Object obj) {
        Matcher matcher = Pattern.compile(pattern).matcher(String.valueOf(obj));
        return matcher.matches();
    }
}

Related

  1. isIp(final String input)
  2. isIP(String input)
  3. isIp(String ip)
  4. isIP(String ip)
  5. isIp(String ipAddress)