Java IP Address Validate isIpValid(String ip)

Here you can find the source of isIpValid(String ip)

Description

is Ip Valid

License

LGPL

Parameter

Parameter Description
ip a parameter

Return

true if the given string is a valid IP address

Declaration

public static boolean isIpValid(String ip) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.regex.Pattern;

public class Main {
    /**/*from   w w w  .j ava2  s.c  o  m*/
     * IP address pattern
     */
    private static final Pattern IP_PATTERN = Pattern
            .compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");

    /**
     * 
     * @param ip
     * @return true if the given string is a valid IP address
     */
    public static boolean isIpValid(String ip) {
        return "localhost".equals(ip) || IP_PATTERN.matcher(ip).matches();
    }
}

Related

  1. isIPv6LiteralAddress(String src)
  2. isIpV6RegexValid(String strIp)
  3. isIPv6StdAddress(final String input)
  4. isIpValid(final String deviceIp)
  5. isIPValid(final String ipv4)