Java IP Address Validate isIpV4StrValid(String str)

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

Description

check if IP v4 string is valid.

License

Open Source License

Parameter

Parameter Description
str IP string(without *).

Return

true if valid, false if not.

Declaration

public static boolean isIpV4StrValid(String str) 

Method Source Code


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

public class Main {
    /**/*from  w w  w.ja v a 2 s.  co  m*/
     * check if IP v4 string is valid.
     * 
     * @param str
     *            IP string(without *).
     * @return true if valid, false if not.
     */
    public static boolean isIpV4StrValid(String str) {
        Pattern pattern = Pattern.compile(
                "^((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]" + ")\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])$");
        return pattern.matcher(str).matches();
    }
}

Related

  1. isIPv4Format(String ip)
  2. isIPv4Format(String str)
  3. isIPv4LiteralAddress(String src)
  4. isIPv4LiteralAddress(String string)
  5. isIpV4PortAddress(String s)
  6. isIPv6(final String ip)
  7. isIPv6(String address)
  8. isIpV6Address(CharSequence address)
  9. isIPv6Address(final String input)