All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.srplib.validation.RegexpValidator Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
package org.srplib.validation;

/**
 * Validates strings with regular expression.
 *
 * @author Anton Pechinsky
 */
public class RegexpValidator extends org.srplib.validation.AbstractValidator {

    private final String regexp;

    /**
    * Creates validators.
    *
    * @param regexp String regular expression.
    */
    public RegexpValidator(String regexp) {
        this.regexp = regexp;
    }

    protected boolean isValid(Validatable validatable) {
        String value = validatable.getValue();
        return value.matches(regexp);
    }

    protected ValidationError newError() {
        // TODO: replace with string formatting
        return Validators.newError("String doesn't match pattern '" + regexp + "'");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy