Asp. NET validation controls

Source: Internet
Author: User

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

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.