package org.bench4q.web.validation;

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


public class ValidateHelper {

	public static boolean validateStringInput(String input) {
		if (input == null || input.length() == 0) {
			return false;
		}
		return true;
	}

	public static boolean validateInteger(String input) {
		Pattern pattern = Pattern.compile("[0-9]*");
		Matcher isNum = pattern.matcher(input);
		return isNum.matches();
	}

	public static boolean validateIp(String input) {
		input.replaceAll(" ", "");
		String ip = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."

		+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."

		+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."

		+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";

		Pattern pattern = Pattern.compile(ip);

		Matcher matcher = pattern.matcher(input);

		return matcher.matches();

	}

	public static void main(String args[]) {
		String ip = "  133.133.12.1";
		System.out.println(validateIp(ip));
		String ipError = "122.122.1.r";
		System.err.println(validateInteger(ipError));
		String number = "123";
		System.out.println(validateInteger(number));
		System.err.println(validateInteger("u7"));
	}

}
