in the computer room charging system, in order to verify whether the text box is empty, whether the user exists, the input is legitimate, etc., we have to write the code alone, learning ASP validation controls that save a lot of things.
ASP validation of user input can be easily achieved. Let's take a good look at the six types of validation controls that are common to ASP.
1 , basic validation controls:
(1) RequiredFieldValidator: Limit empty fields (mandatory field validation) to check for input values
Example: When logging in, you need to verify that the username and password you entered are empty
<asp:requiredfieldvalidator id= "RequiredFieldValidator1" runat= "Server" controltovalidate= "txtUserName" Errormessage= "User name must be entered" ></asp:RequiredFieldValidator>
(2) Basic Comparison Control
a , CompareValidator: comparison of two fields comparison verification) compare two inputs by setting
Example: When we change the password, the first time to enter the password and the second input is consistent, you can use this control.
<asp:comparevalidator id= "CompareValidator1" runat= "Server" controltocompare= "TxtPassword1" controltovalidate= " TxtPassword2 "errormessage=" two times password inconsistency ></asp:CompareValidator>
b , RangeValidator: checks whether the specified range (range validation) input is in the specified range
For example: Enter the range size of the information
For example: Enter the range size of the information
(3) RegularExpressionValidator: check values with regular expressions (regular expression validation) regular expression validation controls
(4) CustomValidator: Check values (custom validation) by client or server functions custom validation controls
3 , validation summary control
(1) ValidationSummary: List validation errors (validation summary) for all controls in the page summary validation results
Example: summary of all validation information
<span style= "font-family:kaiti_gb2312; Background-color:rgb (255, 255, 255); " > </span>
Page.IsValid Properties:
<scrip language= "C #" runat= "Server" >void subbtn (Object src,eventarge E) {if (page.isvalid==true) <span style= " White-space:pre "></span>{lblmessage.text=" page valid ";}} </script>
Page: The current entire page, any one without validating its value is false.
Summarize:
Each validation control performs a specific type of validation and displays a custom message prompt when validation fails. Validation controls provide a great help to our development, and we can validate various validations without requiring too much code.
Asp. NET validation controls