I want to validate a passField but in a runtime and depens on some boolean arguments (capital, digits and alfa).
I decided to implements a Validator (just override apply method) but i found a problem with search a ValidationResut implementation so i decided to use the AbstracValidator.
@Override
public ValidationResult apply(String value, ValueContext context) {
ValidationResult result = this.toResult("", true);
if(capital) {
result = new RegexpValidator("al menos una mayúscula", "\\w*[A-Z]
\\w*")
.apply(value, context);
}
if(!result.isError() && digit) {
result = new RegexpValidator("al menos un dígito", "\\w*\\d\\w*")
.apply(value, context);
}
if(!result.isError() && alfa) {
result = new RegexpValidator("al menos un carácter no alfanumérico", "\\w*[^a-zA-Z0-9]
\\w*")
.apply(value, context);
}
return result;
}
is there another way to obtain a ValidationResult without using toResult method of AbstractValidator?
Is there another better implementation of that to validate passField?