-->
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.  [ 5 posts ] 
Author Message
 Post subject: Validator for String
PostPosted: Mon Mar 16, 2009 7:54 am 
Beginner
Beginner

Joined: Wed Nov 12, 2008 12:07 pm
Posts: 21
Hello

I have a constraint for a String attribute, like String city that can only be "New York" or "Orlando"...
I believe that this would be made using a check constraint for the city column in the ER world, but how can I make it with Hibernate Validator?

I checked the documentation for the basic validators but didn't find.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 8:10 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
You could use a regex-pattern that is going to be validated:
Code:
@Pattern(regex="\QNew York\E|\QOrlando\E")


Rating is welcome. ;-)

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 2:17 pm 
Beginner
Beginner

Joined: Wed Nov 12, 2008 12:07 pm
Posts: 21
Yes, that works, thank you!
However, it does not produce any changes to the db schema. I would like something to create a 'check' constraint in the column of the table, is that possible?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 27, 2009 7:45 am 
Regular
Regular

Joined: Tue Feb 17, 2009 5:13 am
Posts: 59
Sorry my ignorance, but how must I write the regexp including "\Q" or "\E\? if I write only one backslash it raises a compilation error. Should I duplicate it or what?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 28, 2009 9:02 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Yes, in Java you have to duplicate it, because one "\" is an escape-character in java. Sorry, in my post I forgot to do it.

_________________
-----------------
Need advanced help? http://www.viada.eu


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

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.