Asp. NET validation Control Hsiang solution

Source: Internet
Author: User
Tags comparison expression integer range regular expression uppercase letter valid
Asp.net| control ASP. NET is Microsoft's next generation of web development tools, its powerful features immediately attracted a large number of Web developers to invest in it.  Now, let's take a look at the ASP.net validation controls, and feel the power of the asp.net, while facilitating our current web development. Web developers, especially ASP developers, have been annoyed with data validation, and when you finally write the main body of the data submission program, you have to spend a lot of time validating the legality of each user input. If developers are familiar with JavaScript or VBScript, you can use these scripting languages to easily validate, but also consider whether the user's browser supports these scripting languages, and if you are not familiar with these or want to support all user browsers, you must verify in the ASP program, But this validation increases the burden on the server. Now, with ASP.net, you can not only easily validate user input, but also choose to verify on the server side or on the client, no longer need to consider so much, programmers can focus on the design of the main program. Asp.  NET public six kinds of validation controls, respectively, are as follows:
feature description
requiredfieldvalidator (must field validation)
Two input
rangevalidator (range validation) Enter whether the
regularexpressionvalidator (regular expression validation) regular expression validation control
custom validation control
Summary validation results
Next, let's look at the use of these controls one: RequiredFieldValidator (must field validation) use the RequiredFieldValidator control for the following standard code:
placeholder
In the above standard code: ControlToValidate: Indicates that you want to check the control ID; errormessage: Represents an error message that occurs when a check is not valid; display: How the error message is displayed  The static indicates that the error message of the control occupies a positive position on the page; dymatic indicates that the control error message occupies the page control when it appears, none is displayed when the error occurs, but can be displayed in the validatorsummary; PLACEHOLDER: When the display is static, the error message occupies a page space of "placeholder"; Now let's look at an example:
* Name must be entered
In the above example, check that the Txtname control has input, and if not, display the error message "name must be entered." Is it simple? Note: The code for the above code and the other controls below is best placed in the form, and unlike the ASP, the form is best written like this:
In this way, the form is executed on the server side, and the commit is valid; two: CompareValidator (comparison validation) control comparison control compares the two control's input conforms to the program setting, everybody does not think the comparison only is "equal", although the equality is used most, actually,  The comparison here includes a wide range, and you'll see the standard code. The standard code for comparing controls is as follows:
placeholder
In the above standard code: type represents the data type of the control to be compared; operator represents the comparison (that is, why the comparison is more than just "equal"), there are 7 ways to compare, and the other attributes are the same as the RequiredFieldValidator; Here, pay attention to the difference between ControlToValidate and ControlToCompare, if operate is Greatethan, then, Must be controltocompare greater than controltovalidate is legitimate, this, should understand the meaning of both of them?  Example program please refer to the RequiredFieldValidator control and design it against the standard code. Three: RangeValidator (scope Validation) control to verify that the input is in a certain range, the scope of the MaximumValue (maximum) and Minimunvlaue to determine, the standard code is as follows:
placeholder
In the above code: use MinimumValue and MaximumValue to define the value of the control input, using type to define the type of the control's input values. Four: Regularexpresionvalidator (regular expression) control regular expression validation control is very powerful, you can easily construct the verification method, we first look at the standard code:
In the above standard code, ValidationExpression is the focus, now look at its construction: in ValidationExpression, different characters represent different meanings: "." Represents any character, and the "*" representation is in conjunction with other expressions, represents an easy combination; "[A-z]" denotes any uppercase letter; "D" means an easy number; Note that in the above expression, the quotation marks are not included; For example: regular expression: ". *[a-z]" means that any character combination that begins with a number is then followed  An uppercase letter. Five: ValidationSummary (validation summary) the control collects all validation error messages on this page, and can organize them to be displayed later. The standard code is as follows:
"
In the above standard code, Headtext corresponds to the table's Headtext,displaymode indicating how the error message is displayed: The list corresponds to <BR> in HTML; bulletlist equivalent to HTML <LI> Singleparegraph indicates how the error message is not split; Vi. CustomValidator (custom validation) control the control uses a custom function to define the authentication method, with the following standard code:
placeholder
In the above code, the user must define a function to validate the input. Seven: Summarize ASP. NET validation controls have been introduced, you can find that they are very powerful, and no longer worry about verification. Of course, the above introduction is not particularly detailed, subtle places, but also invite you to read the Microsoft SDK.

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.