ASP.NET: Syncing client and server-side validation rules
Are there any easy, smart ways to keep your client and server-side validation-rules synchronized?
On the server-side we have ASP.NET WebForms or ASP.NET MVC.
What is validated are things like:
- Correct e-mail-addresses
- Correct home-addresses and postal codes
- Correct credit-card numbers
And so on.
You can try using Enterprise Library Validation with ASP.NET integration.
write a large, common corpus of test data that embodies the validation rules, and unit test your validators against this common data.
When your rules change, you reflect this by updating the test data and testing until everything goes green again.
I have always used the built in validators. For example if you use a RegularExpressionValidator and supply a ValidationExpression it will validate on client side (if available) and server side using the same code.
You can write your own custom validators by deriving from BaseValidatior. Doing this allows you to create Server Valdiation by overriding EvaluteIsValid. You can then add client validation later if it is necessary.
xVAL is quite a bit easier than the Enterprise Library Validation and handles model bound validation for both Client and Server.