/** * Validates the provided input against the given black list patterns * * @param input input * @param blackListPatterns a String array of black list pattern keys * @return true if does not match with any of the black list patterns */ public static boolean isValidOverBlackListPatterns(String input, String... blackListPatterns) { if (ArrayUtils.isEmpty(blackListPatterns)) { throw new IllegalArgumentException("Should provide at least one black list pattern"); } if (StringUtils.isEmpty(input)) { return true; } validatePatternKeys(blackListPatterns); boolean isValid = false; for (String key : blackListPatterns) { isValid = !validatorConfig.getPattern(key).matcher(input).matches(); if (!isValid) { break; } } return isValid; }
/** * Validates the provided input against the given white list patterns * * @param input input * @param whiteListPatterns a String array of white list pattern keys * @return true if matches with any of the white list patterns */ public static boolean isValidOverWhiteListPatterns(String input, String... whiteListPatterns) { if (ArrayUtils.isEmpty(whiteListPatterns)) { throw new IllegalArgumentException("Should provide at least one white list pattern"); } if (StringUtils.isEmpty(input)) { return true; } validatePatternKeys(whiteListPatterns); boolean isValid = false; for (String key : whiteListPatterns) { isValid = validatorConfig.getPattern(key).matcher(input).matches(); if (isValid) { break; } } return isValid; }