Validation QuickStart

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

The Validation Application Block QuickStart contains two applications which demonstrate some of the key features of the Validation Application Block. The QuickStart walkthroughs are implementations of the key scenarios for the application block, and illustrate the following:

  • Using attributes to define validation rule sets.
  • Using self validation to define validation rules within your classes.
  • Validating objects.
  • Integrating the Validation Application Block with ASP.NET.
  • Integrating the Validation Application Block with Windows Forms.
  • Integrating the Validation Application Block with WCF.

System Requirements

To build and run the QuickStart, you need the following:

  • Microsoft Windows XP Professional, Windows Server 2003, or Windows Vista operating system
  • Microsoft .NET Framework, version 2.0 or 3.0
  • Microsoft Visual Studio 2005 development system
  • ASP.NET, to run the ASP.NET Validation QuickStart.

Building and Running the QuickStarts

The QuickStarts ship as source code, which means you must compile them before running them. You use Visual Studio to build the QuickStarts.

To build the Validation Application Block QuickStarts

  1. Ensure the Enterprise Library Source Code has been installed.
  2. Open the Enterprise Library Source Code folder from Windows Explorer, or from the Start Menu shortcut: on the taskbar, click Start, point to All Programs, point to Microsoft patterns and practices, point to Enterprise Library 3.1 – May 2007 and select Enterprise Library 3.1 Source Folder.
  3. Open the QuickStarts folder, then Validation, then CS (for C#) or VB (for Visual Basic .NET). From there, open either the ValidationAspNetQuickStart folder, or the ValidationQuickStart folder.
  4. Open the solution (.sln) for the project you have chosen. On the Build menu, click Rebuild Solution. By default, this is a debug build.
  5. Press F5 to run the QuickStart.

QuickStart Configuration

The walkthroughs in the Validation QuickStarts include predefined configuration files, which are located in the main folder of each respective project. The ValidationAspNetQuickStart application configuration settings are stored in the standard Web.config file. For logistical reasons, the ValidationQuickStart application has two different configuration files, Designtime.App.config, and Runtime.App.config. Make all configuration changes to Designtime.App.config, as Runtime.App.config is not intended to be directly edited.

Validation Rule Set Definitions

Validators can be applied to classes in two ways, either through configuration files, or by applying attributes to class members. In the Validation QuickStart applications, these approaches are demonstrated by two rule sets: "RuleSetA" and "RuleSetB." "RuleSetA" has been defined by applying attributes to members of the Customer and Address classes in the ValidationQuickStart.BusinessEntities project. "RuleSetB" has been defined using configuration, in the file ValidationQuickStart.BusinessEntities.dll.config. This configuration is loaded into the Windows Forms and ASP.NET QuickStarts using a FileConfigurationSource defined in the runtime.app.config and Web.config files, respectively. The Windows Forms QuickStart also includes a file Designtime.App.config which uses a different relative path to the ValidationQuickStart.BusinessEntities.dll.config, allowing the configuration to be edited during design time.

The ValidationQuickStart.BusinessEntities, and ValidationQuickStart.CustomValidator sub-projects are referenced by both of the validation QuickStart applications. Thus, changes made to the sub-projects are reflected in both the ASP.NET and Windows Forms QuickStart versions.

Configuration Settings

Data Access Application Block Configuration

The default connection string is configured as follows:

  • Name: LocalSqlServer
  • ProviderName: System.Data.SqlClient
    • Data Source: .\SQLEXPRESS
    • Integrated Security: SSPI
    • AttachDBFilename: |DataDirectory|aspnetdb.mdf
    • User Instance: True

Validation Application Block Configuration

The Address class is configured as follows:

  • Name: Address
  • Type: ValidationQuickStart.BusinessEntities.Address
  • RuleSetB
    • City

    • String Length Validator

    • LowerBound: 1

    • LowerBoundType: Inclusive

    • Negated: False

    • UpperBound: 30

    • UpperBoundType: Inclusive

    • Contains Characters Validator

    • CharacterSet: 1234567890!@#$%^&*()-=

    • ContainsCharacters: Any

    • Negated: True

    • MessageTemplate: City may not contain numbers or punctuation characters

    • Not Null Validator

    • Negated: False

    • Line 1

    • String Length Validator 1+

    • LowerBound: 1

    • LowerBoundType: Inclusive

    • Negated: False

    • UpperBound: 0

    • UpperBoundType: Ignore

    • Line 2

    • Or Composite Validator

    • String Length Validator : 0-50

    • LowerBound: 0

    • LowerBoundType: Inclusive

    • Negated: False

    • UpperBound: 50

    • UpperBoundType: Inclusive

    • Null Validator

    • Negated: True

      The Customer class is configured as follows:

  • Name: Customer
  • Type: ValidationQuickStart.BusinessEntities.Customer
  • RuleSetB
    • Address
    • Object Validator
    • TargetRuleSet: RuleSetB
    • DateOfBirth
    • DateRange Validator
    • LowerBound: 1/1/1969
    • LowerBoundType: Inclusive
    • Negated: False
    • UpperBoundType: Ignore
    • MessageTemplate: Must be born after 1969
    • Email
    • Regex Validator
    • Options: None
    • Pattern: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
    • MessageTemplate: Invalid e-mail address
    • FirstName
    • String Length Validator
    • LowerBound: 0
    • LowerBoundType: Ignore
    • Negated: False
    • UpperBound: 20
    • LastName
    • Or Composite Validator
    • Starts with X RegEx Validator
    • Options: None
    • Pattern: X.*
    • MessageTemplate: Last name must start with "X"
    • Ends with z RegEx Validator
    • Options: None
    • Pattern: z*.
    • MessageTemplate: Last name must end with "z"
    • RewardPoints
    • Divisible By 10
    • Collection (Key: Divisor, Value: 10)
    • Tag: Warning
    • Type: ValidationQuickStart.CustomValidators.DivisibleByValidator, ValidationQuickStart.CustomValidators, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

To change or view these settings, use the Enterprise Library Configuration Console to open the configuration file in the directory that contains the QuickStart project file. Each time you build the code, Visual Studio copies the configuration file to the output directory for the project (the same directory where the QuickStart executable is created), and renames it to ValidationQuickStart.exe.config.

This means that if you want to use the configuration console to change any of the configuration settings, and you are planning to rebuild the solution, you must change the settings by opening the App.config file located in the QuickStart source directory. You can use the configuration console to open the ValidationQuickStart.exe.config file and change the application configuration. However, these changes will be overwritten during the next successful build.

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.