Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation annotation for indicating that a checkbox is checked

I have a custom object that represents my form like:

public class RegisterForm {

    @NotNull(message = "Account name cannot be empty.")
    @Size(min = 3, max = 50, message = "Account name must be between 3 and 50 characters long.")
    private String accountName;


    private boolean termsConditions;
}

My controller looks like:

public ModelAndView create(@Valid AccountForm accountForm, BindingResult bindingResult, HttpServletRequest request) {

}

So I added the boolean termsConditions that will be for a checkbox on the form.

What is the annotation I should use to ensure this value is true? i.e the checkbox is checked.

like image 922
Blankman Avatar asked Jan 12 '23 05:01

Blankman


1 Answers

That would be javax.validation.constraints.AssertTrue. From JavaDoc:

The annotated element must be true. Supported types are boolean and Boolean

like image 124
Pavel Horal Avatar answered Jan 17 '23 11:01

Pavel Horal