Verify:
First, RequiredFieldValidator: Non-null verification
ErrorMessage: Error message displayed when verifying an error
ControlToValidate: The control ID to validate
Display: Rendering mode. static-Still, does not display also will occupy the space. dynamic-dynamic, does not display the non-occupied space
InitialValue: The initial value of the control, if the validated value is the same as the initial value, it is also judged to be empty
Two types of non-empty forms:
1. No content
Errormessage,controltovalidate,display
2. The initial value does not change
Errormessage,controltovalidate,display,initialvalue
Second, CompareValidator: Comparative verification
ErrorMessage: Error message displayed when verifying an error
ControlToValidate: The control ID to validate
Display: Rendering mode. static-Still, does not display also will occupy the space. dynamic-dynamic, does not display the non-occupied space
ControlToCompare: The ID of the control to compare
ValueToCompare: A fixed value to compare
Operator: operator, comparison operation on values
Type: Types of inputs and comparisons
Two kinds of contrasting forms:
1. Compare the values of the two controls. --Password and Confirm password
2. The value of the control is compared to a fixed one. --More than 0 monthly income
Two kinds of contrasting forms:
1. Equivalent comparison. --is equal. Operator=equeal (default)
2. No equivalent comparison. --whether a relationship is satisfied. Operator=greaterthan,lessthan .....
Three, RangeValidator, scope validation:
ErrorMessage: Error message displayed when verifying an error
ControlToValidate: The control ID to validate
Display: Rendering mode. static-Still, does not display also will occupy the space. dynamic-dynamic, does not display the non-occupied space
MaximumValue: Range Upper Value
MinimumValue: The lower value of the range
Type: Types of input and validation
Case: Birthdays can only be between 1900-1-1 and 2099-12-31
Four, regularexpressionvalidator_ regular expression validation.
ErrorMessage: Error message displayed when verifying an error
ControlToValidate: The control ID to validate
Display: Rendering mode. static-Still, does not display also will occupy the space. dynamic-dynamic, does not display the non-occupied space
ValidationExpression: The regular expression of the certificate of verification.
V. CustomValidator: Custom Validation
ErrorMessage: Error message displayed when verifying an error
ControlToValidate: The control ID to validate
Display: Rendering mode. static-Still, does not display also will occupy the space. dynamic-dynamic, does not display the non-occupied space
ClientValidationFunction: The JS function name of the client used for custom validation (note no parentheses)
Definition of client-side validation functions
Function name (A, B)
{
B.value-The value in the validated control.
B.isvalid-Tell the browser to verify that it passed. The true-is passed, and the error message is not displayed. The false-does not pass and displays an error message.
}
Example: Verifying prime numbers.
Vi.. ValidationSummary: Validation Rollup control
ShowMessageBox: Whether to display error messages with dialog boxes
ShowSummary: Whether to display error summary information on the page
Several important difficulties and solutions:
1. Validation grouping: Sets the validationgroup of the input control, validation control, button control to the same value, then they are in a group.
2. Block button excitation verification:
Law One: Group buttons individually
Method Two: Set the Causevalidation property of the button to False
3. Verify the error display * and display the error message using the dialog box.
Source:
<%@ page language= "C #" autoeventwireup= "true" codefile= "ShuRuYanZheng.aspx.cs" inherits= "Shuruyanzheng"%>
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<style type= "Text/css" >
. auto-style1 {
height:30px;
}
</style>
<body>
<form id= "Form1" runat= "Server" >
<div>
<br/>
Red display: RequiredFieldValidator, "empty" or "unchanged original value" to Judge <br/>
Blue Display of:comparevalidator
<br/>
Compared with other data, the comparison of ControlToCompare with other controls; <br/>
ValueToCompare compared to the exact value <br/>
Yellow Display of:rangevalidator A comparison with a specified range <br/>
The:regularexpressionvalidator of green reality Comparison with regular expressions <br/>
<br/>
<br/>
<table width= "70%" border= "1" cellpadding= "5" cellspacing= "0" align= "center" >
<tr height= ">"
<TD width= "20%" align= "right" > User name:</td>
<TD width= "45%" >
<asp:textbox id= "Textname" runat= "Server" width= "100%" ></asp:TextBox>
</td>
<TD width= "35%" >
<asp:requiredfieldvalidator id= "RequiredFieldValidator1" runat= "Server" controltovalidate= "Textname" display= " Dynamic "errormessage=" user name cannot be empty! "Forecolor=" Red "></asp:RequiredFieldValidator>
</td>
</tr>
<tr height= ">"
<TD width= "20%" align= "right" > User name 2::</td>
<TD width= "45%" >
<asp:textbox id= "Textname2" runat= "Server" width= "100%" >< required ></asp:TextBox>
</td>
<TD width= "35%" >
<asp:requiredfieldvalidator id= "RequiredFieldValidator2" runat= "Server" controltovalidate= "Textname2" display= " Dynamic "errormessage=" cannot be filled! "Initialvalue=" < required > " Forecolor= "Red" ></asp:RequiredFieldValidator>
</td>
</tr>
<tr height= ">"
<TD width= "20%" align= "right" > Password:</td>
<TD width= "45%" >
<asp:textbox id= "TEXTPWD1" runat= "Server" width= "100%" ></asp:TextBox>
</td>
<TD width= "35%" >
<asp:requiredfieldvalidator id= "RequiredFieldValidator3" runat= "Server" controltovalidate= "TEXTPWD1" display= " Dynamic "errormessage=" Password cannot be empty! "Forecolor=" Red "></asp:RequiredFieldValidator>
</td>
</tr>
<tr height= ">"
<TD width= "20%" align= "right" > Confirm password:</td>
<TD width= "45%" >
<asp:textbox id= "TEXTPWD2" runat= "Server" width= "100%" ></asp:TextBox>
</td>
<TD width= "35%" >
<asp:comparevalidator id= "CompareValidator1" runat= "Server" controltocompare= "TEXTPWD1" controltovalidate= " Textpwd2 "display=" Dynamic "errormessage=" Confirm password input is incorrect! "Blue" ></asp:CompareValidator> forecolor=
</td>
</tr>
<tr>
<TD width= "20%" align= "right" class= "Auto-style1" > Mailbox:</td>
<TD width= "45%" class= "Auto-style1" >
<asp:textbox id= "Textemail" runat= "Server" width= "100%" ></asp:TextBox>
</td>
<TD width= "35%" class= "Auto-style1" >
<asp:regularexpressionvalidator id= "RegularExpressionValidator1" runat= "Server" controltovalidate= "Textemail" Display= "Dynamic" errormessage= "input mailbox is not correct!" "Forecolor=" Green "validationexpression=" \w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) * "></asp:RegularExpressionValidator>
</td>
</tr>
<tr height= ">"
<TD width= "20%" align= "right" > Phone number:</td>
<TD width= "45%" >
<asp:textbox id= "Texttel" runat= "Server" width= "100%" ></asp:TextBox>
</td>
<TD width= "35%" >
<asp:regularexpressionvalidator id= "RegularExpressionValidator2" runat= "Server" controltovalidate= "Texttel" Display= "Dynamic" errormessage= "input phone number is incorrect" forecolor= "Green" validationexpression= "^[1][358]\d{9}$" ></asp: Regularexpressionvalidator>
</td>
</tr>
<tr height= ">"
<TD width= "20%" align= "right" > ID number:</td>
<TD width= "45%" >
<asp:textbox id= "Textshen" runat= "Server" width= "100%" ></asp:TextBox>
</td>
<TD width= "35%" >
<asp:regularexpressionvalidator id= "RegularExpressionValidator3" runat= "Server" controltovalidate= "Textshen" Display= "Dynamic" errormessage= "ID number is incorrect! "Forecolor=" Green "validationexpression=" \d{17}[\d| X]|\D{15} "></asp:RegularExpressionValidator>
</td>
</tr>
<tr height= ">"
<TD width= "20%" align= "right" > Monthly income:</td>
<TD width= "45%" >
<asp:textbox id= "Textmoney" runat= "Server" width= "100%" ></asp:TextBox>
</td>
<TD width= "35%" >
<asp:comparevalidator id= "CompareValidator2" runat= "Server" controltovalidate= "Textmoney" display= "Dynamic" Errormessage= "input is not correct! Positive integers greater than 0 "forecolor=" Blue "operator=" GreaterThan "type=" integer "valuetocompare=" 0 "></asp:CompareValidator>
</td>
</tr>
<tr height= ">"
<TD width= "20%" align= "right" > Birthday:</td>
<TD width= "45%" >
<asp:textbox id= "Textbir" runat= "Server" width= "100%" ></asp:TextBox>
</td>
<TD width= "35%" >
<asp:rangevalidator id= "RangeValidator1" runat= "Server" controltovalidate= "Textbir" display= "Dynamic" Errormessage= "Input time is not within the specified range! "Forecolor=" Yellow "maximumvalue=" 2099-12-31 "minimumvalue=" 1800-1-1 "type=" Date "></asp:RangeValidator>
</td>
</tr>
<tr height= ">"
<TD colspan= "3" align= "Center" >
<asp:button id= "Tijiao" runat= "Server" text= "commit"/>
<br/>
<asp:validationsummary id= "ValidationSummary1" runat= "Server"/>
</td>
</tr>
</table>
</div>
</form>
</body>
Custom validation:
<%@ page language= "C #" autoeventwireup= "true" codefile= "Custom validation. Aspx.cs" inherits= "Custom Validation"%>
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<script language= "JavaScript" >
function Sushuyanzheng (A, B)
{
var n =parseint (B.value);
var c = 0;
for (var i = 1; i < n; i++)
{
if (n% i = = 0)
C + +;
}
if (c = = 1)
{b.isvalid = true;}
else {b.isvalid = false;}
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:textbox id= "TextBox1" runat= "Server" ></asp:TextBox>
<asp:button id= "Button1" runat= "Server" text= "button"/>
<asp:customvalidator id= "CustomValidator1" runat= "Server" clientvalidationfunction= "Sushuyanzheng" Controltovalidate= "TextBox1" display= "Dynamic" errormessage= "is not a prime number! "></asp:CustomValidator>
</div>
</form>
</body>
Validation of entries entered at login in C#--web