HTML5 Validation Dialect - Supported constraints

Constraint Usage Before After
javax.validation.constraints.Size @Size(min = 5, max = 10) <input type="text" name="code" /> <input type="text" name="code" pattern=".{5,10}" required="required" />
javax.validation.constraints.Min @Min(value = 18) <input type="text" name="age" /> <input type="number" name="age" min="18" />
javax.validation.constraints.Max @Max(value = 65) <input type="text" name="age" /> <input type="number" name="age" max="65" />
javax.validation.constraints.Digits @Digits(integer = 3, fraction = 2) <input type="text" name="price" /> <input type="text" name="price" pattern="([0-9]{1,3}\.?|\.[0-9]{1,2}|[0-9]{1,3}\.[0-9]{1,2}){1}" />
javax.validation.constraints.NotNull @NotNull <input type="text" name="code" /> <input type="text" name="code" required="required" />
org.hibernate.validator.constraints.NotEmpty @NotEmpty <input type="text" name="code" /> <input type="text" name="code" required="required" />
org.hibernate.validator.constraints.NotBlank @NotBlank <input type="text" name="code" /> <input type="text" name="code" required="required" />
org.hibernate.validator.constraints.Range @Range(min = 0, max = 10) <input type="text" name="rank" /> <input type="range" name="rank" min="0" max="10" />
org.hibernate.validator.constraints.Length @Length(min = 1, max = 10) <input type="text" name="rank" /> <input type="text" name="rank" pattern=".{1,10}" required="required" />
org.hibernate.validator.constraints.Email @Email <input type="text" name="userEmail" /> <input type="email" name="userEmail" />
org.hibernate.validator.constraints.URL @URL(protocol = "https") <input type="text" name="website" /> <input type="text" name="website" pattern="^https://.+(:[0-9]+)?(/.*)?" />


Back to home page