Validation for web can be a problem. This recipe will explore using closures to support the easy mocking of validation functions and to allow flexibility in the type of validation performed when initializing a controller structure as described by the previous recipe.
We'll perform this validation on a structure, but not explore how to populate the structure. We can assume that the data will be populated by parsing a JSON payload, populating explicitly from the form input, or other methods.