I need i password with the constrains of four digits.
So i create a passwordFields an i add aRegexpValidator with the regular expression “\d{4}”
PasswordField pass = new PasswordField("usuario");
pass.addValidator(new RegexpValidator("\\d{4}", "La contraseña debe tener cuatro caractéres numéricos"));
But if i left the field empty the error message doesn’t appear (the field pass the validation).
It fails if i put “1” , “abc”, …
Musn’t it null fail the validation? Why not in this case?
Hello José,
as docimentation states for RegexpValidator: “An empty string or a null is always accepted - use the required flag on fields or a separate validator (or override isValidValue(String)) to fail on empty values.” https://vaadin.com/api/com/vaadin/data/validator/RegexpValidator.html