The techniques used here are very rudimentary, but effective nonetheless.
Check the method used in the above code By simply putting the JS code to perform the validation will do the validation.
There is a on Submit event that will be invoked when you press a submit button, call the validating code (keep that as a function) so that it will be invoked just before passing the data from the client to the server.
The main goal of Thymeleaf is to provide an elegant and well-formed way of creating templates.
In order to achieve this, it is based on XML tags and attributes that define the execution of predefined logic on the , instead of explicitly writing that logic as code inside the template.