-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Pattern Validator
PostPosted: Tue Apr 30, 2013 4:56 pm 
Newbie

Joined: Tue Apr 30, 2013 4:45 pm
Posts: 1
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 ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.