From the course: Java EE: Bean Validation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Numerical constraints introduction

Numerical constraints introduction

From the course: Java EE: Bean Validation

Start my 1-month free trial

Numerical constraints introduction

- The range for numerical constraints provided out of the box is quite extensive, and number 10. They can be divided into three sub-categories. Those that constrain on number boundaries, those that constrain on a number sign, and those that constrain on the size of a field. Okay, so let's start looking at those that test boundaries. Those that constrain on boundaries require a maximum or minimum value to be specified. That forms the conclusive limit. There are five constraints in this category. Let's have a look at some of these examples. The max annotation specifies a number that the value of the field or property should not exceed. It can be less than or equal to the number past the annotation. In this example, the value of the field must not exceed 100. You can combine max and min to set upper and lower boundaries. And they only operate on integer numbers. For decimal numbers, there are two alternative constraints that do exactly the same job. Decimal max and decimal min. The…

Contents