Java IP Address Validate isIP4(String val)

Here you can find the source of isIP4(String val)

Description

is IP

License

Apache License

Declaration

public static boolean isIP4(String val) 

Method Source Code


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

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static final String IP4_REGEXP = "^(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)$";

    public static boolean isIP4(String val) {
        boolean result = false;

        Pattern p = Pattern.compile(IP4_REGEXP);
        Matcher m = p.matcher(val);
        try {/*from   ww  w . ja  v  a 2  s .c  om*/
            return m.matches();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }
}

Related

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