If you're tired of writing custom validation code for every input field in your applicationsand of fixing the resulting validation errorsthen you'll welcome the generic validation engine described in this article, which can automate many validation scenarios.
by Michael Sorens
January 12, 2007
nput validation is something that every program needs, and every programmer dreads. Most developers craft hard-coded program logic to verify that a phone number consists of 7 or 10 digits; that an IP address consists of 4 octets; that a country name matches 1 of 193 choices, etc. While .NET 2.0 provides some support for streamlining input validation, it barely scratches the surface of automating and simplifying the input validation process. If you ever search MSDN for the topic, you'll find most of the articles discuss hard-coded validationbut maintaining hand-written, custom code for each element that requires validation is a maintenance nightmare.
Furthermore, it's unnatural to conceptualize the steps of validation as programming steps (i.e. if this then that...); it's far more intuitive to consider the qualities of the data to be validated. For example, if you were describing the input, you might say, "It should be between five and eight characters; it should be numeric and non-negative; it should always end in the digit '5,' etc."
It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com. Already a member?
To become a member of DevX.com create your Member Profile by completing the form below. Membership is free!