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
and msg2
are displayed.
Any suggestions?
Thanks!
Just use the annotation @Min
in your bean:
@Min(value = 0L, message = "The value must be positive")
private Double value;