Different ways of Validating ASP.NET Forms

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.

Validation Controls
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/validation/default.aspx

Validating Form Input Control
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/validation/default.aspx

How do I: Use Validation Control in ASP.NET
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/validation/default.aspx

 

ASP.NET AJAX ValidatorCallout

ValidatorCallout is an ASP.NET AJAX extender that enhances the functionality of existing ASP.NET validators.

Validator Callout demonstration
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ValidatorCallout/ValidatorCallout.aspx

How Do I: Use the ASP.NET AJAX ValidatorCallout Extender
http://www.asp.net/ajax/ajaxcontroltoolkit/
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 Number.
  • 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.

http://quickstarts.asp.net/Futures/ajax/doc/validation.aspx

 

Subsonic Validation

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.

http://blogs.msdn.com/gblock/archive/2007/10/01/web-client-validation-bundle-shipped.aspx

 

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:

  • ASP.NET
  • Windows Forms
  • Windows Communications Framework (WCF)

http://msdn2.microsoft.com/en-us/library/bb410105.aspx


Validation Application Block in Enterprise Library 3.0 – Using Validation Facade Class – Part I

Validation Application Block in Enterprise Library 3.0 – ValidationFactory Class – Part II

Validation Application Block in Enterprise Library 3.0 – Ruleset

 

.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.

http://docs.nettiers.com/Default.aspx?Page=EntityLayer&AspxAutoDetectCookieSupport=1#Entity_Validation_Rule_Engine_17

 

Conclusion

Here we have identified a handful amount of Validation Framework, it is true that all of them are very powerful and very well done.