org.srplib.validation.RegexpValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of srp-validation-support Show documentation
Show all versions of srp-validation-support Show documentation
Single Responsibility Principle (SRP) libraries collection
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 + "'");
}
}