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) 

Source Link

Document

Construct a case sensitive validator that matches any one of the set of regular expressions.

Usage

From source file:com.nagarro.core.validator.RegexpValidator.java

@Override
public void validate(Object o, Errors errors) {
    Assert.notNull(errors, "Errors object must not be null");
    final String fieldValue = (String) errors.getFieldValue(getFieldPath());

    RegexValidator validator = new RegexValidator(getRegularExpression());

    if (!validator.isValid(fieldValue)) {
        errors.rejectValue(getFieldPath(), getErrorMessageID(), new String[] { getFieldPath() }, null);
    }/*from   w w  w .  j a v  a 2 s  .c o m*/
}

From source file:com.easyvalidation.rules.impl.ExpressionRule.java

@Override
/**//from   ww  w  .ja  v a 2  s.c o  m
 * Checks for error. As per parameter regEx, if true then regular expression otherwise OGNL.
 */
public final boolean checkError() {
    if (isRegEx()) {
        if (!Utils.isEmpty(getValue())) {
            regexValidator = new RegexValidator(getExpression());
            return !regexValidator.isValid(getValue().toString());
        }
    } else {
        return !OgnlExpressionEvaluator.getValue(expression, parameters);
    }
    return false;
}

From source file:eu.vranckaert.worktime.activities.account.AccountRegisterActivity.java

/**
 *
 * @return//  ww w .j  ava2  s  .  c om
 */
private boolean validateInput() {
    registrationError.setVisibility(View.GONE);

    ContextUtils.hideKeyboard(AccountRegisterActivity.this, email);
    ContextUtils.hideKeyboard(AccountRegisterActivity.this, firstName);
    ContextUtils.hideKeyboard(AccountRegisterActivity.this, lastName);
    ContextUtils.hideKeyboard(AccountRegisterActivity.this, password);
    ContextUtils.hideKeyboard(AccountRegisterActivity.this, passwordConfirmation);

    String firstName = this.firstName.getText().toString().trim();
    String lastName = this.lastName.getText().toString().trim();
    String email = this.email.getText().toString();
    String password = this.password.getText().toString();
    String passwordConfirmation = this.passwordConfirmation.getText().toString();

    if (StringUtils.isBlank(firstName) || StringUtils.isBlank(lastName) || StringUtils.isBlank(email)
            || StringUtils.isBlank(password) || StringUtils.isBlank(passwordConfirmation)) {
        registrationError.setText(R.string.lbl_account_register_error_all_fields_required);
        registrationError.setVisibility(View.VISIBLE);
        return false;
    }
    if (!EmailValidator.getInstance().isValid(email)) {
        registrationError.setText(R.string.lbl_account_register_error_invalid_email);
        registrationError.setVisibility(View.VISIBLE);
        return false;
    }
    RegexValidator rv = new RegexValidator("[A-Za-z0-9_\\-]*");
    if (!rv.isValid(password)) {
        registrationError.setText(R.string.lbl_account_register_error_password_characters);
        registrationError.setVisibility(View.VISIBLE);
        return false;
    }
    if (password.length() < 6 || password.length() > 30) {
        registrationError.setText(R.string.lbl_account_register_error_password_invalid_length);
        registrationError.setVisibility(View.VISIBLE);
        return false;
    }
    if (!password.equals(passwordConfirmation)) {
        registrationError.setText(R.string.lbl_account_register_error_password_confirmation);
        registrationError.setVisibility(View.VISIBLE);
        return false;
    }

    return true;
}

From source file:org.apache.ambari.view.capacityscheduler.PropertyValidator.java

private boolean validateUrl(String[] schemas, String urlString) {
    RegexValidator authorityValidator = new RegexValidator(AUTHORITY_REGEX);
    UrlValidator validator = new UrlValidator(schemas, authorityValidator, UrlValidator.ALLOW_LOCAL_URLS);
    return validator.isValid(urlString);
}

From source file:org.apache.ambari.view.hive.PropertyValidator.java

private boolean validateURL(String webhdfsUrl, String[] schemes) {
    RegexValidator authority = new RegexValidator(".*");
    UrlValidator urlValidator = new UrlValidator(schemes, authority, UrlValidator.ALLOW_LOCAL_URLS);
    return urlValidator.isValid(webhdfsUrl);
}

From source file:org.apache.ambari.view.utils.ambari.ValidatorUtils.java

public static boolean validateURL(String webhdfsUrl, String[] schemes) {
    RegexValidator authority = new RegexValidator(".*");
    UrlValidator urlValidator = new UrlValidator(schemes, authority, UrlValidator.ALLOW_LOCAL_URLS);
    return urlValidator.isValid(webhdfsUrl);
}

From source file:org.apache.rave.portal.web.validator.WidgetValidator.java

public WidgetValidator() {
    super();/*from  w w  w  .  j  a va2 s .  co m*/
    RegexValidator regex = new RegexValidator(new String[] { "http", "https", "((localhost)(:[0-9]+))" });
    urlValidator = new UrlValidator(regex, 0);
}

From source file:org.apache.rave.portal.web.validator.WidgetValidatorTest.java

@Test
public void testValidation() throws Exception {
    RegexValidator regex = new RegexValidator(
            new String[] { "http", "https", "((localhost)(:[0-9]+))", ".*\\.linux-server(:[0-9]+)" });
    UrlValidator validator = new UrlValidator(regex, 0);
    assertTrue("localhost URL should validate",
            validator.isValid("http://localhost:8080/demogadgets/CTSSResourcesMapView.xml"));
    assertTrue("127.0.0.1 should validate",
            validator.isValid("http://127.0.0.1:8080/demogadgets/CTSSResourcesMapView.xml"));
    assertTrue("my.linux-server should validate",
            validator.isValid("http://my.linux-server:8080/demogadgets/CTSSResourcesMapView.xml"));

    assertFalse("broke.my-test should not validate", validator.isValid("http://broke.my-test/test/index.html"));

    assertTrue("www.apache.org should still validate",
            validator.isValid("http://www.apache.org/test/index.html"));
}

From source file:org.codehaus.griffon.runtime.validation.constraints.UrlConstraint.java

@Override
@SuppressWarnings("SuspiciousToArrayCall")
public void setParameter(@Nonnull Object constraintParameter) {
    RegexValidator domainValidator = null;

    if (constraintParameter instanceof Boolean) {
        url = (Boolean) constraintParameter;
    } else if (constraintParameter instanceof String) {
        url = true;//from  w  ww.j  a v  a  2s .com
        domainValidator = new RegexValidator((String) constraintParameter);
    } else if (constraintParameter instanceof List<?>) {
        url = true;
        List<?> regexpList = (List<?>) constraintParameter;
        domainValidator = new RegexValidator(regexpList.toArray(new String[regexpList.size()]));
    } else {
        throw new IllegalArgumentException("Parameter for constraint [" + VALIDATION_DSL_NAME
                + "] of property [" + constraintPropertyName + "] of class [" + constraintOwningClass
                + "] must be a boolean, string, or list value");
    }

    validator = new UrlValidator(domainValidator,
            UrlValidator.ALLOW_ALL_SCHEMES + UrlValidator.ALLOW_2_SLASHES);

    super.setParameter(constraintParameter);
}