views:

1279

answers:

6

Are there any easy, smart ways to keep your client and server-side validation-rules synchronized?

On the client side we have JavaScript, maybe some kind of framework like jQuery or YUI.

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.

+2  A: 

<asp:RegularExpressionValidator ...> (and the other asp.net validators) implement client side javascript and server side checking to the same rules.

ballpointpeon
What server-side check does it do? And how does this work with ASP.NET MVC.
Seb Nilsson
All the validators in ASP.NET work on both the client and server side, because only doing client validation would be a huge security hole. I haven't tried using the validators in MVC.
Brad Wilson
+1  A: 

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.

Dan Vinton
+1  A: 

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.

Shaun Bowe
+1  A: 

This is not a real-world solution, but check out the Axial project on CodePlex. It is a project that converts C# to Javascript for the web, and has a control that lets you use the same code for server side validation and client side validation. It's not ready for production, but I'm curious to see if this is what you're looking for.

Dan Goldstein
+2  A: 

You can try using Enterprise Library Validation with ASP.NET integration.

davogones
I haven't tested it yet, but looking around blogs and articles this seems to be the closest one can get.
Seb Nilsson
+1  A: 

xVAL is quite a bit easier than the Enterprise Library Validation and handles model bound validation for both Client and Server.

Aaron