Client validation

As a little bonus, client-side validation has become very easy nowadays with the HTML5 form validation specification. If your target browsers are Internet Explorer 10 and above, adding client-side validation is as easy as specifying the correct input type instead of just using text.

By adding the client-side validation, we can prevalidate the form and avoid overloading the server with requests that we know are incorrect. More information on the client-side validation specification is available at http://caniuse.com/#search=validation.

We can modify our inputs to enable simple client-side validation. The previous inputs, as shown in the following code:

<input th:field="${profileForm.twitterHandle}" id="twitterHandle" type="text" ...

Get Spring MVC: Designing Real-World Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.