Originally published at: http://www.sitepoint.com/thinking-outside-dom-composed-validators-data-collection/
In part 1 of this mini-series, we discussed a problem common to many validation libraries: tightly coupled code. Then, I introduced you to the benefits of separating orthogonal concerns. As a proof of concept, we started the development of a form validation system that is not restricted to forms, and can even work outside the DOM altogether.
In this second and last part, we’ll discuss composed validators, how to collect data from a form, and how to report errors. Finally, I’ll provide you a link to the GitHub repository containing all the code developed in this mini-series.
Composed Validators
In the previous article we developed a system for validating individual fields. Validating fields one-by-one with one rule at a time is fine and dandy, but there are many cases that require some more thought. You can validate an email address with one insanely long regular expression, but doing so will only enable you to tell your users whether the email is acceptable or not. A better approach is to validate several parts of the email address separately and provide a targeted email validation error.
This is possible with the current design:
Continue reading this article on SitePoint