Java IP Address Validate isIPAddress(String line)

Here you can find the source of isIPAddress(String line)

Description

Checks if a string is a ip address

License

MIT License

Parameter

Parameter Description
line a parameter

Declaration

public static boolean isIPAddress(String line) 

Method Source Code

//package com.java2s;
/**//from w  w w .  j  a  v  a  2s  . co  m
 * This software is licensed under the MIT license.
 * If you wish to modify this software please give credit and link to the git: https://github.com/Moudoux/OTIRC.
 */

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

public class Main {
    /**
     * Checks if a string is a ip address
     * 
     * @param line
     * @return
     */
    public static boolean isIPAddress(String line) {
        Pattern p = Pattern.compile(
                "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");
        Matcher m = p.matcher(line);
        if (m.find()) {
            return true;
        }
        return false;
    }
}

Related

  1. isIpAddress(String ip)
  2. isIPAddress(String ipAddress)
  3. isIpAddress(String ipAddress)
  4. isIpAddress(String ipAddress)
  5. isIPAddress(String ipAddress)
  6. isIpAddress(String str)
  7. isIPAndPort(String text)
  8. isIpFormat(String ip)
  9. isIPSect(String ip)