Combining client-side and server-side validation
When dealing with real web forms we usually need to do various kinds of validation on multiple fields. Some fields may only need checks that can be performed at the client side, while some might also require server-side validation.
In this recipe, we're going to design and implement our own validation plugin that supports asynchronous validation. It will work similarly to jQuery Validate. We're also going to implement some basic validation methods such as required
, minLength
, and remote
.
We're going to use these methods on a simple user registration form, which will be blocked from submission until the user enters valid data in all fields.
Getting ready
The first step in our design process is to design the data structures that will be used in our validator. We're going to make an API similar to jQuery Validate, which takes a configuration object as its parameter. However, we're going to opt into a more modern, HTML5 approach where the validation...