Validate if greater then zero - using valdr-bean-validation

2.3k views Asked by At

I would like to make sure that totalAmount is greater then 0.
I have following code to in my Java bean:

@NotNull(message = "Total amount must be entered")
@Digits(integer = 8, fraction = 2, message = "Please enter a valid amount less than 99,999,999.99")
@DecimalMin(value = "0.01", message = "Please enter a valid amount more than 0")
private BigDecimal totalAmount;

Unfortunately valdr-bean-validator (tool to use JSR-303 with AngularJS) doesn't support @DecimalMin or @DecimalMax. Is there any other way to create the rule for values greater then zero?

EDIT: please note that totalAmount is BigDecimal

2

There are 2 answers

0
FazoM On

I couldn't solve it with JSR-303. I finally implemented custom valdr validator.
It is shame that such common case (value equal to zero) is not supported.

0
Vaclav Stengl On

This should do.

@DecimalMin(value = "0", inclusive = false) by default incluside is true