Input Validation Framework for .NET

The intention is to create an input validation framework for .Net applications.

There are very few and marginaly useful validation tools available, with most of them buing built for WWW applications, and generally tied to hard-coded validation rules. Also, they tend to expose just enough functionality to validate a single input field as a "standalone entity", without putting the validation rules into a bigger context or validating logically-related fields together.

I have found the need in some of my projects not only to separate the validation logic from the presentation, but also to have the ability to configure the validation logic from an external resource without having to recompile and redistribute the application. This, coupled with the need for complex, contextual and conditional validation requirements, has prompted me to write a relatively simple framework to do the job.

For example, say you have a form that captures user information for some sort of contractual agreement.

The form captures:

salutation/title

first name

last name

phone number

address 1

address 2

address 3

social security number

national ID or passport number

email address

Now you ship your application to two different sites in different countries. For a start, the formats of the phone number, social security number, and national ID / passport fields are different between site A and site B. Not only, but also each site has different requirements: site A is not bothered about capturing national ID / passport information, but wants the email address field to be mandatory; conversely, site B is not bothered about capturing email addresses, but national ID / passport is critical to them.
Also, assume that at this stage neither site is bothered about the salutation field.

What do you do?

You could ship two different versions of the application, but surely that's not a convenient and sustainable solution. What if you have 20 business units, each with different validation requirements? Do you build, ship and maintain 20 versions of the application? Nightmare!

Alternatively, you could hard-code the validation logic in the form and switch it on or off according to an external resource file or config file, with hard-coded validation in a big case statement to see which business unit is executing the code, but you've got to do that for each control in the form, in case one of the sites decides that all of a sudden the salutation field must be mandatory
This is ok if you have a form with a handful of controls, but what happens when you have a lot more?
And what happens when you need to make a little adjustment to some control's validation logic? And what if the company decides to open a new business unit somewhere in the world? You need to reopen the code, rebuild, test and ship.

So here's the idea: decoupling the validation logic from the application. How about a validation framework that simply processes validation rules against generic containers? These rules can be defined in an external configuration file, which can also drive the dependency injection for the generic containers at runtime.

When you ship the application (and the validation framework) to "N" sites, they can each configure their own validation rules as needed, and change them as and when required, without the need for the application developers to change a single line of code. The only time you would open the code is to do proper code maintenance/patching or to work on the next release, but you would never have to open the code to reconfigure any of the input validation stuff.