How are people doing their validations on data?
Basically I have a requirement that to apply for insurance you need to be over 14 years of age.
Now, on the application form you may need to not only enter your age but any nominated drivers date of births as well.
I went through the Nerd Dinner example and it works but I was wondering whether anyone is doing other types of validations.
You can use DataAnnotations to attach validation to objects directly.
Validating with Data Annotation Validators
You can get fancy by creating custom data annotations which will then allow you to create validation on fields of a certain type.
So for your age requirement;
So;
Your model could then decorate the field;
Then in your view;
Then your Controller could look like this;
This is a bit more work but you no longer need to call a method yourself everytime you wanted to validate some data.
It also means that all applications that use this model will apply the same business rule to your ages thus providing consistency across the organisation.
I actually happened to have the above handy to some respect. I use it a lot in my objects. Do remember to wrap this in a Try / Catch.