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. The datatype of the newly added field is Integer instead of the primitive type int as it will help in making the field required and handling type conversion errors.

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