What are the different validators in ASP.NET?
--
ASP.NET validation controls validate the user input data to ensure that useless, unauthenticated, or contradictory data don’t get stored.
The validation control is used to implement a page level validation in server controls.
There are 6 types of ASP.Net Validation Control:
- RequiredFieldValidator
- RangeValidator
- RegularExpressionValidator
- CompareValidator
- ValidationSummary
- CustomValidator
- RequiredFieldValidator
Indicates the input Control is not empty when the form is submitted.
Syntax
<asp:RequiredFieldValidator ID="someUniqueId"
runat="server" ControlToValidate ="someUniqueControlId"
ErrorMessage="ErrorToDisplayOnValidationFailure"
InitialValue="aPlaceholderValue">
</asp:RequiredFieldValidator>
2. RangeValidator
The Rangevalidator control is verifies that the input value falls within a given range of number, date or string.
Syntax
<asp:RangeValidator ID="some unique id"
runat="server" ControlToValidate ="someUniqueControlId"
ErrorMessage="ErrorToDisplayOnValidationFailure"
Type="Integer" MinimumValue=”0” MaximumValue=”100”>
</asp:RangeValidator>
3. RegularExpressionValidator
The RegularExpressionValidator control validates the input text of a control that matches a pattern defined by a RegularExpression.
Syntax
<asp:RegularExpressionValidator ID="someUniqueId"
runat="server" ControlToValidate ="someUniqueControlId"
ErrorMessage="ErrorToDisplayOnValidationFailure"
ValidationExpression=”aRegexPattern”>
</asp:RegularExpressionValidator>
4. CompareValidator
The Comaprevalidator control compares the value of one control to another using a comparison operator.
Syntax
<asp:CompareValidator ID="someUniqueId"
runat="server" ControlToValidate ="someUniqueControlId"
ErrorMessage="ErrorToDisplayOnValidationFailure"
Type="string" ControlToCompare=”ControlToValidateIdOfAnotherControl”
ValueToCompare=”aFixedValue” Operator=”Equal”>
</asp:CompareValidator>
5. CustomValidator
ASP.Net also allows the freedom of writing your own validator. This eases the task of a developer to validate the form at the client side itself. It also allows putting more complex validations in place. Validations that are business or application-specific can be written using custom validators.
Syntax
<asp:CustomValidator ID="someUniqueId"
runat="server" ControlToValidate ="someUniqueControlId"
ErrorMessage="ErrorToDisplayOnValidationFailure"
ClientValidationFunction=”functionName”>
</asp:CustomValidator>
6. ValidationSummary
The ValidationSummary control doesn’t perform any validation. Instead, it shows a summary of errors raised by each control on the page.
Syntax
<asp:ValidationSummary ID="ValidationSummaryControl"
runat="server" DisplayMode=”BulletList” ShowSummary=”true”
HeaderText=”List of Errors” />
If you have any query regarding ASP.NET Development services then hire ASP.NET Developers from Rlogical Techsoft.
Learn more in details here: https://www.educba.com/asp-dot-net-validation-controls/