?
Solved

ValidationExpression

Posted on 2009-07-13
9
Medium Priority
?
588 Views
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

ValidationExpression="{Yes|No}"

But it does not seem to work
0
Comment
Question by:Mr_Shaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 28

Expert Comment

by:strickdd
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.
0
 

Author Comment

by:Mr_Shaw
ID: 24842111
I am using a dropdown list.

The list items are:

--Please Select--
Yes
No
0
 

Author Comment

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

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

0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 15

Assisted Solution

by:mohan_sekar
mohan_sekar earned 80 total points
ID: 24842222
simple <asp:RequiredFieldValidator will do for you
0
 

Author Comment

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

thanks
0
 
LVL 28

Accepted Solution

by:
strickdd earned 1920 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:DropDownList>
<asp:RequiredFieldValidator runat="server" ControlToValidate="MyDDL" Text="Required" Display="Dynamic"/>

Open in new window

0
 

Author Comment

by:Mr_Shaw
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?
0
 
LVL 28

Assisted Solution

by:strickdd
strickdd earned 1920 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 -->
0
 

Author Closing Comment

by:Mr_Shaw
ID: 31602927
thanks
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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