.NET/ASP.NET Interview Question – Elaborate with examples different types of validators available in ASP.NET?


A validator is a computer program used to check the validity or syntactical correctness of a fragment of code or text.

IN ASP.NET there are six different types of Validators.

1.Required Field Validator.

2.Regular Expression Validator.

3.Compare Validator.

4.Range Validator.


6.Validation Summary

RequiredFieldValidator:-Ensure that the control has a value to assign in it or user does not skip an entry.

For Example:-

 <asp:Textbox id="txtMobileNumber" runat="server"></asp:Textbox>
 <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
 ErrorMessage="Mobile Number is a required field."

Regular ExpressionValidator:-Ensure that the value of the control matches the expression of validator that is specified. This
type of validation enables you to check for sequence of character, such as e-mail address, telephone number, postal code and so on.

For Example:-

 <asp:TextBox ID="txtE-Mail" runat="server"></asp:TextBox>
 <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
 ErrorMessage="Please Enter a Valid E-Mail" 
 ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"> // for internet E-Mail.

Ensure that the value of one control should be equal to value of another control.which is commonly used in password,less than,greater than or equal to.

For Example:-

<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<asp:TextBox ID="txtConfirmPassword" runat="server"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" 
ControlToCompare="txtPassword" ControlToValidate="txtConfirmPassword" 
ErrorMessage="Password does not match">

RangeValidator:-Ensures that the value of the control is in specified lower and upper boundaries or specified range.  You can check ranges within pairs of numbers, alphabetic characters.

For Example:-

<asp:TextBox ID="txtAmount" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" 
ErrorMessage="RangeValidator" MaximumValue="5000" 

This control is used to perform user defined

ValidationSummary:-This validator is used to displays a detailed summary on the validation errors that currently exist.

Please click here to see more .NET/ASP.NET interview questions


Visit Authors blog for more ASP.NET interview questions


About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
This entry was posted in Uncategorized and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s