Validating user input is a very common task that we perform during web page development, and in the ASP.NET world we have a handful amount of choices to perform validation.
ASP.NET Validation Controls
ASP.NET ships with a handful amount ASP.NET Validation controls such as RequiredFieldValidator, CompareValidator, RangeValidator, RegularExpressionValidator, CustomValidator and ValidationSummary.
These controls are very easy to hook up with other ASP.NET controls, and if properly configured they check input for possible errors, and display error messages to notify the user. There are lots of articles available on how to use the these controls, the ASP.NET Quickstart articles are really good too.
Validating Form Input Control
How do I: Use Validation Control in ASP.NET
ASP.NET AJAX ValidatorCallout
ValidatorCallout is an ASP.NET AJAX extender that enhances the functionality of existing ASP.NET validators.
Validator Callout demonstration
How Do I: Use the ASP.NET AJAX ValidatorCallout Extender
Configuring this one is also time consuming and has to be done for each input controls.
ASP.NET AJAX Futures: Validators
The Futures release provides a number built-in validation controls:
requiredFieldValidator. Checks that data was entered.
typeValidator. Checks the type of the data, such as
rangeValidator. Checks the input value between an upper and lower bound.
customValidator. Defines a custom expression handler.
regexValidator. Checks the data using a regular expression. The regular expression value must be delimited with “/” characters.
SubSonic has one tier of validation – based on your database Schema. Kevin details how to make use of SubSonic’s out of the box solution and how to customize it to emulate Rails/Django-like model validation. Read more.
Validation Everywhere (CodePlex)
Project Validation Everywhere´s purpose is to create a framework for declarative validation, so you can use the same validation logic through all the different environments that your Business Layer might be running against.
This project started mainly because of NMVP project (NMVP Project). I do a lot of MVP UI´s, and they really help in the direction of creating UI unit tests. One part of the UI that is overlooked in the testing is the validation since it´s done by ASP.Net and it´s validators.
Web Client Validation Bundle
The guidance in this bundle is designed to help you streamline the end-user experience of your web applications by utilizing ASP.NET AJAX to invoke server-side validation. Additionally you will find guidance on how to improve maintainability of your applications by reusing domain object validations across multiple screens, applications and tiers. You’ll also find a set of guidelines on how to perform security validation in order to protect your sites from SQL Injection, Cross-Site scripting, etc. Like the Contextual Autocomplete Bundle, this guidance is applicable for both WCSF and standard ASP.NET non-WCSF based solutions.
Enterprise Library 3.0 Validation Block
The Enterprise Library Validation Application Block provides a library of classes, called validators, that supplies the code for validating .NET Framework data types. For example, one validator checks for null strings and another validator checks that a number falls within a specified range.
There are three ways to perform validation within the application block, and to create rule sets. They are:
- Using configuration
- Using attributes
- Using code
In addition, the Validation Application Block includes adapters that allow you to use the application block with the following technologies:
- Windows Forms
- Windows Communications Framework (WCF)
.NetTier Validation Rule Engine
One of the most powerful features that .netTiers provides to manage the integrity of your data is the Entity Rule Engine. This implements IDataErrorInfo in the EntityBase.generated.cs class. It provides the framework for managing entity business rules and custom error information that a user interface can bind to. Controls such as the DataGridView automatically detect this interface and provide error icons along with descriptions about the error.
There are several properties that assist you in managing your business rules. There are several built in validators ready to use out of the box.
- NotNull – Determines the if the database column accepts null values.
- StringMaxLength – Compares against the column width for the property.
- StringRequired – Determines if the column allows empty string entries.
- MaxWords – Determines whether the property has exceeted the maximum number of words
- RegexIsMatch – Determines whether current property matches the regular expression
- LessThanOrEqualToValue – Less than or equal to current value of property
- LessThanValue – – Less than current value of property
- EqualsValue – Equals current value of property
- GreaterThanValue – Greater than current value of property
- GreaterThanOrEqualToValue – Greater than or equal to current value of property
- CompareValues – Compares values of T using a comparer
- InRange – Ensures T is within a min and max of a Range using a Comparer.
Here we have identified a handful amount of Validation Framework, it is true that all of them are very powerful and very well done.