package at.gv.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.regex.Pattern;

public class ValidationUtils {

	private static final String DATEFORMAT = "dd.MM.yyyy";
	
	public static boolean isDateFormat(String dateString) {
		
		if (dateString.length() > DATEFORMAT.length())
			return false;
		
		SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
		try {

	    sdf.parse(dateString);
	    return true;
    } catch (ParseException e) {
	    return false;
    }
		
	}
	
	public static boolean isEmailAddressFormat(String address) {
		if (address == null) {
			return false;
		}
		return Pattern.compile("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$").matcher(address).matches();
	}
	
	public static boolean containsPotentialCSSCharacter(String param) {
		if (param == null) {
			return false;
		}
		return param.indexOf(";") != -1 ||
					 param.indexOf("%") != -1 ||
					 param.indexOf("\"") != -1 ||
					 param.indexOf("'") != -1 ||
					 param.indexOf("ยด") != -1 ||
					 param.indexOf("`") != -1 ||
					 param.indexOf(",") != -1 ||
					 param.indexOf("<") != -1 ||
					 param.indexOf(">") != -1 ||
					 param.indexOf("\\") != -1 ||
					 param.indexOf("#") != -1 ||
					 param.indexOf("/") != -1;
					 
					 
	}
	
	public static boolean isValidPostCode(String postcode) {
		if (postcode == null)
			return false;
		
		return Pattern.compile("[0-9]{4}").matcher(postcode).matches();
	}
	
}