Asp.net uses regular expressions and verification controls to verify that the text box value is not empty and is a number

Source: Internet
Author: User
Asp.net has a verification control to help us verify the data in the form. Below we will explain an example of digital verification to give us a rough understanding of the validation control in Asp.net. Step 1: Add the following controls to the page:

One Textbox (ID is the default textbox1), one button (ID is the default button1), one requiredfieldvalidator (verify and fill in), and one regularexpressionvalidator (verify whether it is a number ). The following two controls are

You can find.

Step 2: Modify the attributes of the two verification controls.

The modified requiredfieldvalidator control is as follows:

Display indicates the layout, static and dynamic. The former indicates static, and the latter indicates dynamic. Generally, dynamic is used, dynamic means that when the former meets the verification conditions while the latter does not, the latter's position will automatically change according to the layout, in our example, the error message displayed in the latter will be automatically moved to the left. As shown in:

The second control is modified as follows:

Among them, the more important thing is validationexpression, which indicates the validation expression. Here we enter:

^ [1-9] \ D * $

Indicates that the positive integer is verified.

Running result:

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.