Several validation controls

Source: Internet
Author: User

Several validation controls

Requiredfieldvalidator,comparevalidator,regularexpressionvalidator

RequiredFieldValidator is a control that verifies that a control must be an item. Generally include textbox,combox and so on.

Common properties are

ControlToValidate the control ID to validate

ErrorMessage the message when validation fails

Text displayed when the text control is not valid

Display displays with three values

None indicates that the control does not display information when it is invalid

Static indicates that the validation control occupies a position on the page

Dynamic means that the position of the control on the page is animated and needs to be displayed before it occupies the position.

The use of RequiredFieldValidator is simple, binding the control, setting the display text is fine.

<asp:label id= "Label1" runat= "Server" text= "ID" ></asp:Label>

<asp:textbox id= "txtID" runat= "Server" ></asp:TextBox>

<asp:requiredfieldvalidator id= "RequiredFieldValidator1" runat= "Server"

Controltovalidate= "txtID" display= "Dynamic" errormessage= "ID needed" ></asp:RequiredFieldValidator>

There is a TextBox input box on the page, RequiredFieldValidator bound textbox, set text to

"ID needed" prompts the user to enter the ID display mode for dynamic display.

"ID needed" is prompted when the user does not enter

Compatevalidator is a comparison control that can be used to compare the value of a control to a fixed value whether

Match, or if the value of one control matches the value of another control, the most common is to validate two times

The input value of the password is equal.

The common properties are

ControlToValidate the control ID to validate

ErrorMessage the message when validation fails

Text displayed when the text control is not valid

Display displays with three values

None indicates that the control does not display information when it is invalid

Static indicates that the validation control occupies a position on the page

Dynamic means that the position of the control on the page is animated and needs to be displayed before it occupies the position.

Operateor the operator to use when comparing

Equal Verify that the control value is equal to a constant value or a comparison control value

NotEqual Verify that the control value is not equal to a constant value or to a control value

GreaterThan validation control value is greater than constant value or compared to control value

Greaterthanequal Verify that the control value is greater than or equal to a constant value or compared to a control

LessThan validation control value is less than constant value or compared to control value

Lessthanequal validation control value is less than or equal to constant value or compared to control value

Type comparison when the data type referenced includes a string Integer Date Double Currency

Compatevalidator Code

<asp:label id= "Label2" runat= "Server" text= "Password" ></asp:Label>

<asp:textbox id= "TXTPW" runat= "Server" ></asp:TextBox>

<asp:label id= "Label3" runat= "Server" text= "Again" ></asp:Label>

<asp:textbox id= "TXTPW2" runat= "Server" ></asp:TextBox>

<asp:comparevalidator id= "CompareValidator1" runat= "Server"

Controltocompare= "Txtpw2" controltovalidate= "txtID"

Errormessage= "Password Different" ></asp:CompareValidator>

The page has two textbox for entering two passwords comparevalidator the second input password compared to the first input password, not equal when prompted Password different

RangeValidator

The scope validation control. Verifies that the control value is within a range.

Common properties are

ControlToValidate the control ID to validate

ErrorMessage the message when validation fails

Text displayed when the text control is not valid

Display displays with three values

None indicates that the control does not display information when it is invalid

Static indicates that the validation control occupies a position on the page

Dynamic means that the position of the control on the page is animated and needs to be displayed before it occupies the position.

Maximuvalue the maximum data range to compare

MinimumValue the minimum data range to compare

<asp:label id= "Label5" runat= "Server" text= "age" ></asp:Label>

<asp:textbox id= "txtage" runat= "Server" ></asp:TextBox>

<asp:rangevalidator id= "RangeValidator1" runat= "Server"

Controltovalidate= "Txtage" errormessage= "Out Date" maximumvalue= "1"

Minimumvalue= "></asp:RangeValidator>"

Bind the RangeValidator control to the Age input box, set the range at 1-100 years

When the value entered exceeds this range, the out data is prompted

The functionality of the validation control can also be implemented in code, but it is also easy to control, but the control is used to verify that the data is concise, and that the validation part is separated from the logical part and is easy to maintain later. Which method to use should depend on the actual situation.

Several validation controls

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.