Hi,
I'm just trying Hibernate Pattern Validator. I have written a simple code :
import org.hibernate.validator.Length; import org.hibernate.validator.NotNull; import org.hibernate.validator.Pattern;
public class ValidatePattern {
@NotNull @Length(min=5,max=50) @Pattern(regex="([a-zA-Z0-9]+[\\s]{0,1}[a-zA-Z0-9]*)([a-zA-Z0-9]*[\\s]{0,1}[a-zA-Z0-9]*)*", message="#{messages['company.name']}") private String companyName; public String getCompanyName() { return companyName; }
public void setCompanyName(String companyName) { this.companyName = companyName; }
public static void main(String[] args) { ValidatePattern obj = new ValidatePattern(); obj.setCompanyName("abc"); System.out.println("Check validity ---->"+obj.getCompanyName()); }
}
But when i'm executing this, I'm getting the output :
Check validity ---->abc
Shouldn't i getting some validation error as minimum length which i have define is 5. And also if i'm trying some weird input which should not match my regular expression, it is still showing same output as input. AM i missing anything ? Do i need to make some configurations to make Hibernate validators work ?
|