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.

ASP.Net Validation Control

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

  1. 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/

--

--

--

Web & Mobile App Development Company. Expertise in Mobile App,PHP, ASP.NET, MVC 5 (Razor),MongoDB, NodeJS, AngularJS, ReactJS,Windows App, POS, Scraping.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Improve Your Git Productivity With VS Code

Software Craftsmanship

Everyone who doubts you will always come back around That kid who used to bully you will come…

How we automated our PingCastle security audit reports for our Active Directory

What is WebRTC & why is it useful?

What is WebRTC & why is it useful?

Jenkis Pipeline with GitFlow

SNXweave Weekly Recap

Fourth Project: Javascript

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rlogical Techsoft.Pvt.Ltd

Rlogical Techsoft.Pvt.Ltd

Web & Mobile App Development Company. Expertise in Mobile App,PHP, ASP.NET, MVC 5 (Razor),MongoDB, NodeJS, AngularJS, ReactJS,Windows App, POS, Scraping.

More from Medium

[Dot Net Core](Graphic series )4. MiddleWare — UseEndpoint to Map Controller

Deploy a .NET CORE(5.0/6.0) API on Linux (Ubuntu — EC2 on AWS) — Basic Steps.

Fixing my BF1942 woes with Win32 APIs

How to prevent asp.net core mvc from compile cshtml view when deploying