The benefits of the ASP. NET validation control: 1, the client server side will be verified at the same time. 2, simplify the check logic.
1,requiredfieldvalidator: non-null check
InitialValue: Default value. Cannot pass validation when the value of the control is equal to the default value. Text: Displays the error message.
Controltovalidat: Associates a control that requires validation.
2,rangevalidator: Between the given maximum and minimum values. Type: The type of data that needs to be validated.
MaximumValue: Maximum value.
MinimumValue: Minimum value. Non-null checks are not performed. If you want to make a non-null check, add the RequiredFieldValidator control 3,comparevalidator: To compare whether the relationship between two values satisfies or is a specified type of data. Type: The type of data that needs to be validated. Operator The property value of the comparison operator:
- DataTypeCheck: Comparing data is not this type.
- Equal: equals this value.
- GreaterThan: Greater than this value.
- Greaterthanequl: greater than or equal.
- LessThan: Less than.
- Lessthanequal: Less than equals.
- NotEqual: Not equal to.
ValueToCompare: Compare to which value ControlToCompare: compare to the value of another control. 4,regularexpressionvalidator: Verifies whether the data conforms to the regular expression. Validationexpression:[email protected]+5,customvalidator: Custom validation. Service-Side code:
protected void CustomValidator1_ServerValidate (object source, ServerValidateEventArgs args) { int month = Convert.ToInt32 (txtmonth.text); int day = Convert.ToInt32 (txtday.text); int[] Data ={ --------------------------------- int days = data[month-1]; Args. Isvalid= (Day <= days && Day >= 1); }
Client code:
<script type= "Text/javascript" > function Dayvaild (src,args) { var txtmonth = document.getElementById (" <%=txtmonth.clientid%> "); var month = parseint (Txtmonth.value, ten) var day = parseint (Args.value, ten) var data = [31, 29, 31, 30, 31, 30, 31 ,------ var days = data[month-1]; Args. IsValid = (Day <= days && Day >= 1); } </script>