We've talked about Form Validation several times, most often with Spring as our framework. Here's a screenshot from a Spring Form Validation post from 2015.
Today we're using straight-up Jersey with the Bootique MVC Module, Mustache and Validate.js. As you can see, the end-game is the same.
The Validate JQuery plugin can't be beat for client-side validation. Here's what would happen if we simply clicked the "Sign up" button with validate.js. It also handles field length and formatting requirements.
More Extensive Validation Server-side
We're going to check for existing usernames and email addresses on the server. We also have a custom validator that checks for blocked email address domains like mail.ru.
We perform our checks and if a problem is found, re-populate our FormUser object and send it back to the client. (Yes, we could pack up the FormUser fields and let Mustache extract the object, but will keep things open for purposes of this demo.)
The main item of interest above as we package our Mustache Model is obtaining our errorMessage. If it is contained in the model, Mustache will display it for us.