Simple form verification class ASP Validator

Source: Internet
Author: User
Tags function prototype
Current version: ver 0.1 beta download: http://nowgoo.zhuosong.com/validator.rar 1. ASP Validator introduction ASP Validator is a form verification class based on ASP for form-based server-side verification. For example, to verify whether the value of a text box (assuming the element named UserEmail) in the form is in the correct email format, you may write the code Dim strEmail in the traditional way, objRegExp strEmail = Trim (Request. form ("UserEmail") Set objRegExp = New RegExp With objRegExp. global = False. ignoreCase = True. pattern = "^ w + ([-+.] w +) * @ w + ([-.] w + )*. w + ([-.] w +) * $ "End With If objRegExp. test (strEmail) = False Then Response. write ("invalid email format") Set objRegExp = Nothing End If. When ASP Validator is used, you may Write the following code: D Im objValidator Set objValidator = New Validator objValidator. add "UserEmail", "Email", "invalid Email format", "" If Not objValidator. validate Then Response. write (objValidator. err) Set objValidator = Nothing End If in the above example, although the traditional method is more intuitive and there are not many lines of code, but in actual application, when multiple rules are verified for multiple form elements, you have to write code for each verification rule of each element, although common functions can be written into files to reduce labor intensity, it still takes a lot of time and effort to write repeated code snippets (at least you need to write countless requests. form (""), If Then ,......). In this case, the advantages of ASP Validator are presented.
In the above example, we use the Add method, Validate method, and Err attribute of ASP Validator. When ASP Validator is used, we first Add the rules to be verified through the Add method, then perform the verification through the Validate method and get the verification result, and finally get the error information (if any) through the Err attribute ). In ASP Validator, we divide the entire verification task into several "rules" and Add rules using the Add method. The function prototype of the Add method is as follows: The Public Sub Add (Element, RegType, ErrMsg, Para) Add method contains four parameters: form Element name, rule type, error information, and rule parameters. In the preceding example, the form element is named "UserEmail", the rule type is "Email", the error message is "invalid Email format", and the rule parameter is blank.
Related Article

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.