Validation Controls in ASP.NET

What are Validation Controls?

Validation Controls validate the user input data to ensure that only correct authenticated data gets stored. 

ASP.NET validation controls validate the user input data to ensure that useless, unauthenticated, or contradictory data don't get stored.


Validation Controls List

i) Required Field Validator: This is an elementary validation control. Almost all forms include a few fields that must be filled out by the user in order to continue. To ensure that these fields are not left empty, the Required Field Validator is used.

<asp: RequiredFieldValidator ID="id1" runat="Server" ControlToValidate="t1" ErrorMessage="EnterName" InitialValue="Enter Name">
</asp:RequiredFieldValidator>


ii) RangeValidator: Simply, the RangeValidator control defines the range that the input value may fall. This is mainly beneficial for date or numeral input values such as age.

The RangeValidator control verifies that the input value falls within a predetermined range. It has three specific properties:

<asp: RangeValidator ID="id2" runat="Server" ControlToValidate="age" ErrorMessage="Enter between 18-25" MaximumValue="25" MinimumValue="18" Type="Integer">
</asp: RangeValidator>


iii) CompareValidator: The CompareValidator control compares the value of one control with either a fixed value or a value in another control.

<asp:CompareValidator ID="someUniqueId" runat="server" ControlToValidate ="someUniqueControlId" ErrorMessage="ErrorToDisplayOnValidationFailure" Type="string" ControlToCompare=”ControlToValidateIdOfAnotherControl” ValueToCompare=”aFixedValue” Operator=”Equal”>
</asp:CompareValidator>


iv) RegularExpressionValidator: RegularExpressions, also known as Regex, are patterns that specify how text should be formatted. Regex returns true if the text is in the same format, else it returns false.

The RegularExpressionValidator enables the validation of input text by comparing it to a regular expression's pattern. And the ValidationExpression property contains the regular expression.

<asp:RegularExpressionValidator ID="someUniqueId" runat="server" ControlToValidate ="someUniqueControlId" ErrorMessage="ErrorToDisplayOnValidationFailure" ValidationExpression=”aRegexPattern”>
</asp:RegularExpressionValidator>


v) CustomValidator: The CustomValidator is used to write your own validation. And the validation can be done either on the client side or the server side.

<asp:CustomValidator ID="someUniqueId" runat="server" ControlToValidate ="someUniqueControlId" ErrorMessage="ErrorToDisplayOnValidationFailure" ClientValidationFunction=”functionName”>
</asp:CustomValidator>


vi) ValidationSummary: It doesn't perform any validation. The purpose of ValidationSummary is to display a summary of all the errors on the page.

<asp:ValidationSummary ID="ValidationSummaryControl" runat="server" DisplayMode=”BulletList” ShowSummary=”true” HeaderText=”List of Errors” />
Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad

Below Post Ad