Java IP Address Validate isIp(String str)

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

Description

is Ip

License

Open Source License

Declaration

public static boolean isIp(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 REGEX_IP = "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b";

    public static boolean isIp(String str) {
        return regex(str, REGEX_IP);
    }/*from w  w  w .  ja  v a2  s .  c  o m*/

    public static final boolean regex(String testStr, String regStr) {
        Pattern p = Pattern.compile(regStr);
        Matcher m = p.matcher(testStr);
        return m.matches();
    }
}

Related

  1. isIP(String ipString)
  2. isIp(String s)
  3. isIP(String src)
  4. isIP(String str)
  5. isIp(String str)
  6. isIP4(String val)
  7. isIPAddress(final String s)
  8. isIpAddress(String addr)
  9. isIpAddress(String ip)