Requiredfieldvalidator (field verification required) is used to check whether input values exist.
Comparevalidator (comparison verification) compares two inputs according to Settings
Rangevalidator (range verification) whether the input is in the specified range
Regularexpressionvalidat Or (Regular Expression verification) Regular Expression verification control
Custom verification control
Validationsummary (Verification summary) summarizes verification results
Next, let's take a look at the use of these controls
I. standards used by the requiredfieldvalidator Control for requiredfieldvalidator (field verification is required) Code As follows:
<Asp: requiredfieldvalidator runat = "server"
Controltovalidate = "Name of the control to be checked"
Errormessage = "error message"
Display = "static | dymatic | none"
>
Placeholder
</ASP: requiredfieldvalidator>
In the above standard code:
Controltovalidate: indicates the ID of the control to be checked;
Errormessage: indicates the error message when the check is invalid;
Display: Display Mode of the error message. Static indicates that the error message of the control occupies a certain position on the page. dymatic indicates that the page control is occupied only when the control error message appears; none indicates that the error is not displayed when it appears, but it can be displayed in validatorsummary;
Placeholder: indicates that when the display is static, the error information occupies the page space as large as the "Placeholder;
Now let's look at an instance:
<Asp: textbox runat = "server"/>
<Asp: requiredfieldvalidator runat = "server"
Controltovalidate = "txtname"
Errormessage = "name required"
Display = "static">
* Name is required
</ASP: requiredfieldvalidator>
In the preceding example, check whether the txtname control has been input. If not, an error message "name is required" is displayed ". Is it easy?
Note: The code above and the code of other controls below should be put into form. Unlike ASP, it is best to write form as follows:
<Form runat = "server">
Other code
</Form>
In this way, the form is executed on the server, and the submission will be valid;
2. comparevalidator Control
Compare controls to compare whether the inputs of the two controls match Program In terms of settings, we should not simply think of the comparison as "equal". Although equality is the most commonly used, the comparison here involves a wide range and you will understand the standard code.
The standard code for comparing controls is as follows:
<Asp: comparevalidator runat = "server"
Controltovalidate = "Control ID to be verified"
Errormessage = "error message"
Controltocompare = "Control ID to be compared"
Type = "string | integer | double | datetime | currency"
Operator = "equal | notequal | greaterthan | greatertanequal | lessthan | lessthanequal | datatypecheck"
Display = "static | dymatic | none"
>
Placeholder
</ASP: comparevalidator>
In the above standard code:
Type indicates the Data Type of the control to be compared;
Operator indicates a comparison operation (that is, why it is not just "equal"). Here, there are 7 Comparison methods;
Other attributes are the same as requiredfieldvalidator;
Here, pay attention to the difference between controltovalidate and controltocompare. If operate is greatethan, controltocompare must be greater than controltovalidate. Now, we should understand the meaning of the two? For the example program, refer to the requiredfieldvalidator control and design it according to the standard code.
3. rangevalidator Control
Verify that the input is in a certain range and the range is determined by maximumvalue (maximum) and minimunvlaue. The standard code is as follows:
<Asp: rangevalidator runat = "server"
Controltovalidate = "Control ID to be verified"
Type = "integer"
Minimumvalue = "minimum"
Maximumvalue = "maximum"
Errormessage = "error message"
Display = "static | dymatic | none"
>
Placeholder
</ASP: rangevalidator>
In the above Code:
Use minimumvalue and maximumvalue to define the input value range of the control, and use type to define the type of the input value of the control.
Iv. regularexpresionvalidato R (Regular Expression) Control
Regular Expression verification controls are very powerful. You can easily construct verification methods by yourself. Let's take a look at the Standard Code:
<Asp: regularexpressionvalidat Or runat = "server"
Controltovalidate = "Control name to be verified"
Validationexpression = "Regular Expression"
Errormessage = "error message"
Display = "static"
>
Placeholder
</ASP: regularexpressionvalidat Or>
In the above standard code, validationexpression is the focus. Let's take a look at its structure:
In validationexpression, different characters indicate different meanings:
"." Indicates any character;
"*" Indicates that it is easy to combine with other expressions;
"[A-Z]" represents any capital letter;
"\ D" indicates a number;
Note that quotation marks are not included in the preceding expressions;
Example:
Regular Expression: ". * [A-Z]" indicates a combination of any character starting with a number followed by an uppercase letter.
V. validationsummary Control
This control collects all verification error messages on this page and organizes them to be displayed later. The standard code is as follows:
<Asp: validationsummary runat = "server"
Headertext = "header information"
Showsummary = "True | false"
Diaplaymode = "list | bulletlist | singleparagraph"
>
</ASP: validationsummary>
In the above standard code, headtext is equivalent to the headtext of the table. displaymode indicates that the error message is displayed in the following way: List is equivalent to <br> in HTML; bulletlist is equivalent to <li> in HTML; singleparegraph indicates that error messages are not separated;
6. customvalidator control]
The control defines the verification method using a custom function. The standard code is as follows:
<Asp: customvalidator runat = "server"
Controltovalidate = "control to be verified"
Onservervalidatefunction= "Verification function"
Errormessage = "error message"
Display = "static | dymatic | none"
>
Placeholder
</ASP: customvalidator>
In the above Code, you must define a function to verify the input.