Example usage for org.apache.commons.validator.routines RegexValidator RegexValidator

List of usage examples for org.apache.commons.validator.routines RegexValidator RegexValidator

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines RegexValidator RegexValidator.

Prototype

public RegexValidator(String[] regexs, boolean caseSensitive) 

Source Link

Document

Construct a validator that matches any one of the set of regular expressions with the specified case sensitivity.

Usage

From source file:org.lirazs.gbackbone.validation.client.rule.PatternRule.java

@Override
public boolean isValid(final String text, String attribute) {
    String regex = ruleAnnotation.regex();
    boolean caseSensitive = ruleAnnotation.caseSensitive();
    return new RegexValidator(regex, caseSensitive).isValid(text);
}

From source file:org.mule.extension.validation.internal.validator.MatchesRegexValidator.java

@Override
public ValidationResult validate(MuleEvent event) {
    RegexValidator validator = new RegexValidator(new String[] { regex }, caseSensitive);
    return validator.isValid(value) ? ok() : fail();
}

From source file:org.mule.modules.validation.ValidationModule.java

/**
 * If the specified <code>value</code> does not match any of the regexs then throw an exception.
 * <p/>/*  w  w  w  . j  a v a2s.  co m*/
 * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:validate-using-regex}
 *
 * @param value                    Value to match
 * @param regexs                   Set of regular expressions to test against
 * @param caseSensitive            when true matching is case sensitive, otherwise matching is case in-sensitive
 * @param customExceptionClassName Class name of the exception to throw
 * @throws Exception if not valid
 */
@Processor
public void validateUsingRegex(String value, List<String> regexs,
        @Optional @Default("false") boolean caseSensitive,
        @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName)
        throws Exception {
    RegexValidator validator = new RegexValidator(regexs.toArray(new String[] {}), caseSensitive);

    if (!validator.isValid(value)) {
        throw buildException(customExceptionClassName);
    }
}