I want to allow only positive integers for number fields including zero. How can I define this validation using JSR 303 ?
I tried
@Min(value=0 message = "msg1")
- But it allows float values like 1.2.@Digits(fraction = 0, integer = 10, message ="msg2")
- It accepts negative values.@Min(value=0, message = "msg1" )
@Digits(fraction = 0, integer = 10, message ="msg2")
- It works fine but sometimes both the messages i.e.msg1
andmsg2
are displayed.
Any suggestions?
Thanks!
hibernate-validator
than you may create custom constraint which combine@Min
and@Digits
from 3rd option by using@ConstraintComposition(AND)
. When you add@ReportAsSingleViolation
only your custom message will be shown. – Cassidycassie