Java IP Address Validate isIPAndPort(String text)

Here you can find the source of isIPAndPort(String text)

Description

is IP And Port

License

LGPL

Declaration

public static boolean isIPAndPort(String text) 

Method Source Code

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

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

public class Main {

    public static boolean isIPAndPort(String text) {
        if (isEmpty(text))
            return false;
        String[] texts = text.split(":");
        if (texts.length != 2)
            return false;
        Pattern pattern = Pattern.compile(
                "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))$");
        Matcher matcher = pattern.matcher(texts[0]);
        if (matcher.find()) {
            return texts[1].matches("^(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-5][0-5][0-3][0-5])$");
        }// w w w .  ja  va 2s .  com
        return false;
    }

    public static boolean isEmpty(String text) {
        return (text == null || text.trim().isEmpty());
    }
}

Related

  1. isIpAddress(String ipAddress)
  2. isIpAddress(String ipAddress)
  3. isIPAddress(String ipAddress)
  4. isIPAddress(String line)
  5. isIpAddress(String str)
  6. isIpFormat(String ip)
  7. isIPSect(String ip)
  8. isIPString(String str)
  9. isIpv4(String ipv4)