Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.regex.Pattern;

public class Main {
    public static boolean checkIPAndPort(String ip, String port) {
        boolean ok = true;
        Pattern ipPattern = Pattern
                .compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
                        + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");

        if (!ipPattern.matcher(ip).matches()) {
            ok = false;
        }

        int porti = 0;
        try {
            porti = Integer.parseInt(port);
        } catch (NumberFormatException e) {
            ok = false;
            e.printStackTrace();
        }
        if (porti < 1 && porti > 65535) {
            ok = false;
        }

        return ok;
    }
}