ASP. NET-how to: Verify ASP. NET Server controls against data types

Source: Internet
Author: User

You can verify the user input in the ASP. NET webpage against a specific data type to ensure that the user inputs numbers, dates, and so on. For example, to collect birthdate information on the user registration page, you can use the comparevalidator control to ensure that the date format of the page is recognizable before submission.

1. Add the comparevalidator control to the page and set the following attributes:

Attribute

Description

Controltovalidate

The ID of the control whose data type you want to check.

Errormessage, text, display

These attributes specify the text and location of errors to be displayed when verification fails.

 

2. Set the following attributes to set the data type to be compared:

Attribute

Description

Type

The data type to be checked. Type is specified by the validationdatatype enumeration. This enumeration allows you to use type names such as string, integer, double, date, and currency.

Operator

Datatypecheck

Note: If you leave the control blank, the control passes comparative verification. To force the user to enter a value, add the requiredfieldvalidator control.

 

3. Add a test in ASP. NET webpage code to check the validity.

 

 

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.