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: