Issue
I have this input field in a form which I validate using spring boot validator:
<input class="form-control" th:field="*{numericField}"
type="number" min="0" id="numeric_field_input">
The valid range is all positive numbers. But even if I do not fill in any number, the field validates. I believe the default value is zero. Adding something like
th:default="-1"
did not solve the problem. How can I check on serverside that a user input any value?
These are my current annotations of the field:
@Positive(message = "{validation.numericField.positive}")
@ColumnDefault("0")
private Integer numericField;
Solution
You can use these 2 validations
@NotNull("message": "numericField: positive number value is required")
@Min(value=0, message="numericField: positive number, min 0 is required")
Answered By - anish sharma
Answer Checked By - Mary Flores (JavaFixing Volunteer)