Page 1 of 1

Validation: in presentation tier, middle tier or data tier?

Posted: Wed Aug 26, 2009 9:20 am
by foobaa
Hi,

I'm trying to improve a re-usable Form class I've designed - a little pet project. It's the only piece of code I always end up re-using.

I believe in separation of concerns, and maximum re-use, but like to keep it simple - avoiding frameworks wherever possible.

But I'm having trouble working out where to do certain types of validation. For example, checking for a valid email address. Which tier should this be done at? Presentation, middle or data? Once, twice, or even in all three? Ultimately the error needs to be displayed to the user via the Form object.

Any thoughts very welcome!

Re: Validation: in presentation tier, middle tier or data tier?

Posted: Wed Aug 26, 2009 3:55 pm
by Darhazer
There should be data format validation (e.g. e-mail format, numeric for numeric fields, etc.) in the presentation layer and always data validation in the data layer, which can validate field based on another field (business rules), end of course, escaping before sending to database, again in the data layer.

Re: Validation: in presentation tier, middle tier or data tier?

Posted: Wed Aug 26, 2009 7:33 pm
by foobaa
Thanks - that's interesting - I didn't think the data layer should do any validation of business rules - and I honestly didn't think the presentation layer should be responsible for any error checking at all?