package bruce.lib; import java.util.regex.Pattern; public class Validator { public final static boolean isCreditCard(CharSequence input) { return input == null ? false : Pattern.matches("^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$", input); } public final static boolean isDomain(CharSequence input) { return input == null ? false : Pattern.matches("^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)?$", input); } public final static boolean isFloatingPointNumber(CharSequence input) { return input == null ? false : Pattern.matches("[-+]?([0-9]+\\.?[0-9]*|\\.[0-9]+)([eE][-+]?[0-9]+)?", input); } public final static boolean isGUID(CharSequence input) { return input == null ? false : Pattern.matches("^[\\d\\w]{8}-[\\d\\w]{4}-[\\d\\w]{4}-[\\d\\w]{4}-[\\d\\w]{12}$", input); } public final static boolean isIPAddress(CharSequence input) { return input == null ? false : Pattern.matches("\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b", input); } public final static boolean isLettersOnly(CharSequence input) { return input == null ? false : Pattern.matches("^[[:alpha:]]+$", input); } public final static boolean isMailAddress(CharSequence input) { return input == null ? false : Pattern.matches("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*", input); } public final static boolean isNumeric(CharSequence input) { return input == null ? false : Pattern.matches("^\\d+$", input); } public final static boolean isPhoneNumber(CharSequence input) { return input == null ? false : Pattern.matches("^[\\d-]{7,15}$", input); } public final static boolean isSocialID(CharSequence input) { return input == null ? false : Pattern.matches("^[a-zA-Z]\\d{9}$", input); } public final static boolean isSymbolIncluded(CharSequence input) { return input == null ? false : Pattern.matches("[`~!@#$%^&*\\(\\)_+=-\\|\\[\\]{};':\",\\./<>?]", input); } public final static boolean isUrl(CharSequence input) { return input == null ? false : Pattern.matches("http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?", input); } }