ASP.NET is Microsoft's next-generation web development tool, and its powerful function immediately attracted a large number of Web developers put it down. Now let's take a look at the ASP.NET's verification control, feel the powerful features of ASP.NET, while facilitating our current web development.
Web developers, especially ASP developers, have been more annoyed to data verification. When you don't easily write the main body of the data submission program, you have to spend the time to verify that the user is legal. If developers are familiar with JavaScript or VBScript, you can easily implement verification with these scripting languages, but you must consider whether the user browser supports these scripting languages; if you are not very familiar with or want to support all user browsers, you must be in the ASP program. Verify, but this is verified to increase the server burden. Now, there is an ASP.NET, you can not only easily implement the verification of the user, but also choose to verify that the server is done or on the client, no need to consider so much, programmers can be important Energy is placed in the design of the main program.
ASP.NET has six verification controls, respectively, respectively:
Control Name Function Description RequiredFieldValidator (Multi-Field Verification) is used to check if there is input value comparevalidator (compare verification) Press to set comparison two input RangeValidator (Range Verification) Enter whether it is specified REGLAREXPILALIDATOR (regular expression verification) regular expression Verification Control CustomValidator (Customized Validation) Custom Verification Control Validationsummary (Verification Summary) Summary Verification Result
Below, let's see the use of these controls.
One: Use of RequiredFieldValidator (must be field verification)
The standard code used by the RequiredFieldValidator control is as follows:
Now let's take an example: Note: The above code and the code of the following other controls are best placed in Form, and the ASP is not the same, FORM is best written as this:
In this way, Form is executed on the server side, and submit will be effective;
Two: CompareValidator control
The comparison control compares whether the input of the two controls meets the program settings. Don't understand the comparison is "equal", although the highest is used, in fact, the comparison here includes a wide range, everyone will understand the standard code will understand .
The standard code for the comparison control is as follows:
In the above standard code:
TYPE indicates the data type of the control to be compared;
Operator indicates a comparison operation (that is, why is it more than just "equal" reasons), here, there are 7 ways;
Other properties are the same as required and RequiredFieldValidator;
Here, pay attention to the difference between ControlTovAlidate and ControlToCompare, if Operate is GreateThan, then you must ControlToCompare is legal, this, should you understand the meaning of both? For example, please refer to the RequiredFieldValidator control, the standard code yourself.
Three: RangeValidator (Range Verification) Control
Verify that the input is determined in a certain range, the range is used to determine with MaximumValue (maximum) and minimunvlaue, the standard code is as follows:
In the above code:
Using MinimumValue and MaximumValue to define the control input worth the range, use Type to define the type of control input value.
4: RegularExPResionvalidator (regular expression) control
Regular expression verification control is very powerful, you can easily construct a verification method, let's take a look at the standard code:
In the above standard code, ValidationExpression is the focus, now take a look at its construct:
In ValidationExpression, different characters represent different meaning:
"." Indicates any character;
"*" Indicates that the other expressions indicates easy combination;
"[A-Z]" indicates any existed letters;
"/ d" means easy for a number;
Note that in the above expression, quotation marks are not included;
Example:
Regular expression: ". * [A-z]" indicates any of the characters that start with the number thereafter after one uppercase letter.
Five: Validationsummary (Verification Summary) Control
This control collects all validation error messages on this page and can be displayed later. The standard code is as follows:
In the above standard code, HeadText table corresponding to HeadText, DisplayMode an error message is displayed: List corresponding to the HTML
; BulletList corresponds to the HTML
This control uses a custom function to define the verification mode, its standard code is as follows:
In the above code, the user must define a function to verify the input.
7: Summary
The ASP.NET verification control has been introduced, you can find that their features are very powerful, no longer worry about verification. Of course, the above introduction is not particularly detailed, subtle, please also read Microsoft's SDK.