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 publicly has six verification controls, as follows: The control name function describes the RequiredFieldValidator (Multi-Field Verification) is used to check if there is input value CompareValidator (compare) Press to set two input RangeValidator (Range Verification) input Specifies Range REGLAREXPRESSIONVALIDATOR (Regular Expression Verification) Regular Expression Verification Control CustomValidator (Custom Verification) Custom Verification Control Validationsummary (Verification Summary) Summary Verification results below, let's see these controls
One: RequiredFieldValidator uses the standard code used by the RequiredFieldValidator control as follows:
In this way, Form is executed on the server side, and submit will be valid; two: CompareValidator control comparison control compares whether the input of two controls is in line with the program settings, you don't think of comparison is "equal", although it is The most, in fact, the comparison here includes a wide range, and everyone will understand the standard code. 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 means a comparison operation (which is what is more than just "equal" reason), here, there are 7 ways; other properties and RequiredFieldValidator The same; here, pay attention to the difference between ControlTovAlidate and ControlToCompare, if Operate is GreateThan, then you must have ControlToCompare greater than ControlTovAlidate is legal, this, you should understand the meaning of both? For example, please refer to the RequiredFieldValidator control, the standard code yourself.
Three: RangevaliDator (Range Verification) Control Verification Input is determined at a certain range, the range is used by MaximumValue (maximum) and minimunvlaue, the standard code is as follows:
In the above code: Use MinimumValue and MaximumValue to define the control input value, use Type to define the type of control input value. Four: RegularExPResionvaliDator (regular expression) Control regular expression verification control function 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 look at its construct: in the validationExpression, different characters represent different meaning: "." Indicates any character; "*" indicates one of the other expressions, indicates easy combination "[AZ]" indicates any existed letters; "/ d" means easy for a number; note that quotation marks are not included in the above expression; example: Regular expression: ". * [AZ] Any character combination thereafter after a uppercase letter.
5: Validationsummary Control This control collects all verification error messages of this page and you can organize them 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
Six: CustomValidator (Custom Verification) Control This control is defined to define the verification method, and its standard code is as follows:
7: Summary ASP.NET Verification Control has been introduced, you can find that their function is very powerful, no longer worry about verification. Of course, the above introduction is not particularly detailed, subtle, please also read Microsoft's SDK.