Validation controls in the WebForm

Source: Internet
Author: User

1. Non-null validation controls: Requirefieldvalidator; 2. Data comparison verification: CompareValidator; 3. Data Range Validation: RangeValidator ; 4. Regular expression validation: RegularExpressionValidator; 5. Custom Condition Validation: CustomValidator non-null validation control: Requirefieldvalidator When one accepts the contents of a user-entered control, cannot be empty when using the Requiredfildvalidator control, you must set the following two properties: errormessage: "Required" contrltovalidtor:textbox1 if the control has a "default value" so that he does not enter anything, It is not empty, but for the system the input is 0, you can set the initialvalue= default value of the non-null validation control; If you cannot be a default and cannot be empty at this point, you need two validation controls to validate the input of an input control. The purpose of the validation control is to verify that the control becomes a required control. Data comparison Verification : CompareValidatorFunction: Compares the user's input to a constant value and another control's property value.   Syntax: <asp:comparevalidator id= "Verify control Name" runat= "Server" controltocompare= "Control name" controltovalidate= "compared to the validated control The name of the control being validated "errormessage=" Error prompt ></asp:CompareValidator> properties: controltovalidate: Specifies the input control to validate ControlToCompare: Specifies another input control that is compared to the validated input control type: Determines whether the value entered into the input control can be converted to the data type specified by the Type property. Operator: Allows you to specify the type of comparison to perform, such as greater than, equal to, and so on. Note: If the input control is empty, no validation functions are called and validation succeeds. Use the RequiredFieldValidator control to prevent users from skipping an input control.   Data Range Validation: RangeValidator function: Ensure that the value entered by the user is within the specified upper and lower bounds. Syntax: <asp:rangevalidator id= "Verify control Name" runat= "Server" controltovalidate= "validated control name" display= "display Mode"    Errormessage= "error message" maximumvalue= "Max"      minimumvalue= "min" type= "type" ></asp: Rangevalidator> uses a method similar to CompareValidator for regular expression validation: RegularExpressionValidator syntax: <asp: RegularExpressionValidator id= "Validating control Name" runat= "Server" controltovalidate= "validated input control name"      Errormessage= "Error Prompt"  validationexpression= "Regular expression" ></asp:RegularExpressionValidator> The most important attribute of a regular expression is validationexpression,This property is used to set the regular expression for comparison validation   custom condition validation: Customvalidatorcustomvalidator is used to customize validation rules. You need to use this control to define your own validation logic when the validation controls described earlier do not meet your needs. CustomValidator can be verified either on the server side or on the client    can disable data validation in the following 3 ways: 1. Set the CausesValidation property of the related control to false. 2. Disable the validation control    set the Enabled property of the validation control to false. 3. Disable client-side validation    set the EnableClientScript property of the validation control to false.  

Validation controls in WebForm

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.