Java IP Address Validate isIPAddress(String ipAddress)

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

Description

is IP Address

License

Open Source License

Declaration

public static boolean isIPAddress(String ipAddress) 

Method Source Code

//package com.java2s;
/*//from  w ww . j av  a  2  s.c o  m
 * xAuth for Bukkit
 * Copyright (C) 2012 Lycano <https://github.com/lycano/xAuth/>
 *
 * Copyright (C) 2011 CypherX <https://github.com/CypherX/xAuth/>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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

public class Main {
    public static boolean isIPAddress(String ipAddress) {
        if (ipAddress == null)
            return false;

        Pattern pattern = Pattern.compile("\\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");
        Matcher matcher = pattern.matcher(ipAddress);
        return matcher.matches();
    }
}

Related

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