Posted on 2009-07-13
Last Modified: 2013-12-17
I am trying to configure my regular expression validation control to make sure that the use either selects Yes or No.

I have tried to configure the expression as


But it does not seem to work
Question by:Mr_Shaw
  • 5
  • 3
LVL 28

Expert Comment

ID: 24842085
What type of control are you using? If you are using a radiobuttonlist control, just us a required field validator. If you are using a dropdownlist with a blank option, just use a required field validator. If you are using a TextBox control, switch to a radiobuttonlist or dropdownlist. No need for a regularexpressionvalidator for Yes/No options.

Author Comment

ID: 24842111
I am using a dropdown list.

The list items are:

--Please Select--

Author Comment

ID: 24842151
Ok.. It looks like I can achieve it using the following

                <asp:RangeValidator ID="RangeValidator1" runat="server"
                    ErrorMessage="RangeValidator" MaximumValue="Yes" MinimumValue="No"></asp:RangeValidator>

LVL 15

Assisted Solution

mohan_sekar earned 20 total points
ID: 24842222
simple <asp:RequiredFieldValidator will do for you
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.


Author Comment

ID: 24842239
ok i will check it out in the morning..

LVL 28

Accepted Solution

strickdd earned 480 total points
ID: 24842453
Mohan sekar, thank's for reiterating my point.

Mr Shaw, since I no know you have a drop down list, you can do the following:
<asp:DropDownList ID="MyDDL" runat="server">

   <asp:ListItem Value="" Text=""/>

   <asp:ListItem Value="Yes" Text="Yes"/>

   <asp:ListItem Value="No" Text="No"/>


<asp:RequiredFieldValidator runat="server" ControlToValidate="MyDDL" Text="Required" Display="Dynamic"/>

Open in new window


Author Comment

ID: 24847637
strickdd,,,, I theory I could use the above code. But one of the items in the list is "--Please Select--"  If the user selects the item "--Please Select--"  then it would appear as if they have made a selection.

Is  this correct?
LVL 28

Assisted Solution

strickdd earned 480 total points
ID: 24848390
When using this solution, you can have the initial value of the ddl be ANYTHING you want. If you want it as "--Please Select--" then you just set the TEXT (not the VALUE) to be that. For example:

<asp:ListItem Value="" Text="--Please Select--"/> <!-- NOTE, value is still empty. This is needed to fire the requiredfieldvalidator -->

Author Closing Comment

ID: 31602927

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 48
I need help embedding an image as HTML in my application 3 50
Error in page 3 46
consuming an asmx web service in winforms application 3 26
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now