Validating Numbers

Learn how to validate number fields.

We'll cover the following

In this lesson, we will show how to validate a number field. Currently, we don’t have a number field in the Athlete class. We will add a field rank to store the current ranking the player. The value of rank can be between 1 and 100. Any value outside this range should result in a validation error. We will use @Min and @Max to validate the number range.

@Min and @Max

We will create an Integer field rank and annotate it with @Min and @Max as follows:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.