Form Data Validation

Form data validation is the process of ensuring that the data submitted through a web form is accurate, complete, and adheres to specified rules before it is processed or stored. It prevents invalid data from causing errors or inconsistencies in an application. Data validation includes checking if the required fields are not left blank, numbers are within a given range, and data is entered in the correct format. The Standard Bean Validation API is the preferred approach for validation in Spring applications. We will use the Hibernate implementation of the API known as Hibernate Validator.

Enabling validation

The current version of Hibernate validator is Hibernate Validator 7.x. Spring 5 is not compatible with this release because of differences in package naming convention. Spring 5 uses Java EE packages starting with javax.* while Hibernate Vaildator 7 has changed package names to jakarta.*.

For this reason, we will use an older version of Hibernate Validator that use the javax.* package naming convention. The validator version that is compatible with Tomcat 7 is version 5.1.3. Newer versions of the validator, 6.2.x, can be used with Tomcat 8 or higher.

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