ASP. NET validation control

Source: Internet
Author: User

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>

  

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.