Saturday, January 7, 2012

Simplify with an XML data model - Part 4


Part 4: Client-side data validation using Schematron.
Data validation prevents data corruption and security risks. This often goes beyond simple data type checking of strings and integers, and can consist of complex business rules such as “email address must be valid” or “if the user does not enter a zip code, they must enter a city and state”.

Data must be validated on the server side no matter what, since rich javascript applications can be hacked and manual http requests can be made to the server. Data should also be validated on the client before it is sent to the server. This makes for a better user experience where errors are surfaced to the user before they are sent to the server. Client validation takes load off of the server and makes for a more responsive application. Because it is a nice thing to do validation on both the client and the server, it would be ideal to define these validation rules once and use them in both places.

Interactive example 4: