Enterprise Library-validation Application Block learning Manual (Latest Version) Part 5

Source: Internet
Author: User
This article demonstrates the use of the Enterprise Library-validation Application Block verification management module. The exercise uses the configuration file instead of attribute to specify the validation rules ). This article by the http://blog.entlib.com open source ASP. Net blog platform team according to the entlib Hol manual compilation to provide, welcome to exchange. Exercise 5: Specify verification rules through the configuration fileThe following operations can be performed on the basis of Exercise 4 to delete validation bubutes in the customer and address classes, alternatively, open validationhol in the \ Enterprise Library 4.1 Hol \ CS \ validation \ labs \ lab05 \ before directory. SLN project file. The solution includes two projects: validationhol. businesslogic and validationhol. 1. Create a configuration file to add the configuration file app. config for the validationhol project. 2. Compile solution the purpose of compiling solution is to load the DLL of the application in subsequent steps. 3. Use the configuration editing tool of entlib to add validation configuration to the configuration file. First, add the validation application block to the app. config configuration file, as shown in.
4. Add the validation configuration for the customer class (1) Right-click the validation Application Block node and select new | type to add a new node for the customer type, as shown in.
In the pop-up type selector dialog box, select the load from file button, and find the validationhol. businesslogic. dll file compiled in the previous step (because the package contains the customer class ). In the filter text box, enter customer to find the customer class contained in validationhol. businesslogic. dll, as shown in.
(2) Add a new rule set for the customer type and set the default rule set for the customer type. Right-click the customer node and add a new rule set, as shown in.
Select the Rule Set node and set the name attribute to default, as shown in. Click the customer node and set the defaultrule attribute to default, which is the newly added rule set in the previous step, as shown in.
(3) Right-click a new node for the customer type and choose new | choose members from the shortcut menu, as shown in.
In the pop-up member selector dialog box, select all attributes of the customer class, as shown in.
(4) Right-click the firstname node, select new | String Length validator, and set String Length validator for the firstname attribute, as shown in.
Select the string length validator node and set the following attributes: lowerbound = 1 lowerboundtype = inclusiveupperbound = 25, as shown in.
Repeat the firstname operation to set String Length validator for lastname and set the following attributes: lowerbound = 1 lowerboundtype = inclusiveupperbound = 25. Continue to set Regular Expression validator for the SSN attribute and set the following attributes: pattern = ^ \ D-\ D $ continue to set the object validator for the address attribute, no attribute needs to be set. 5. Follow the steps to set the validation configuration for the customer class and set the validation configuration for the address class. First, add the address type, add a new rule set, and rename it as default. Set this rule set to the default rule set of the address type. The difference is to set and composite validator for the city attribute, as shown in. Click the city attribute and select new | and composite validator.
Click Add composite validator node, add string length validator and contains character validator according to the previous steps, and set the following attributes for String Length validator: lowerbound = 1 lowerboundtype = inclusiveupperbound = 30 set the following attributes for contains character validator: characterset = seacontainscharacters = all continue to set String Length validator for the state attribute: lowerbound = 2 lowerboundtype = inclusiveupperbound = 2 set String Length validator: lowerbound = 1 lowerboundtype for the streetaddress attribute Dtype = inclusiveupperbound = 50 set Regular Expression validator: pattern = ^ \ D {5} $ after the preceding operation is complete, the configuration file is shown in. Remember to save the configuration file.
6. run the sample program and check whether the validation configuration in the configuration file is effective. In the data entry window, if no information is entered, click the accept button to display the error verification error message, as shown in.
Http://www.entlib.com professional ASP. NET e-commerce platform team, welcome to continue to visit the validation Application Block learning manual. Reference:Validation Application Block hands-on labs for Enterprise Library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.