Solved

compare validator asp.net, c#

Posted on 2009-05-08
7
692 Views
Last Modified: 2013-12-17
Hi i have the following code

 <asp:RegularExpressionValidator ID="Year" runat="server" ControlToValidate="txtdate"
            ErrorMessage="Please Enter yyyy-mm" ValidationExpression="(19|20)\d\d-(0[1-9]|1[012])"></asp:RegularExpressionValidator>

which makes sure that the date entered is on yyyy-mm format

i also have two text bos one is txtDate which is start date and the other is txtEnddate,

What i want to do is compare it so that the end date is never less than start bearing in mind the format i have given.

Please help


Thanks,

R8VI
0
Comment
Question by:R8VI
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 15

Expert Comment

by:NazoUK
ID: 24334708
<asp:CompareValidator runat="server" ControlToValidate="txtEndDate" ControlToCompare="txtDate" Operator="GreaterThanEqual" Type="Date" ErrorMessage="End Date must not be before Start Start" />
0
 

Author Comment

by:R8VI
ID: 24334770
Hi,

thanks for thsi but this doens twork in the sense for example if i put 1999-04 as start date and then put 1999-01 as end date the validation works no problem but then if i put in correct information for example as 1999-06 as end date validation will still appear.

Please help

Thanks,

R8VI
0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 24334817
hi R8VI,

               you have add a CompareValidator control in your page, which helps u to compare between your txtDate textBox and textEnddate textBox.
<asp:CompareValidator ID="CompareValidator1" runat="server" 
            ControlToCompare="txtDate" ControlToValidate="textEnddate" ErrorMessage="end date is never less than start" 
            Operator="GreaterThanEqual" Type="Date"></asp:CompareValidator>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 24334858
hi R8VI,
              check the link for regular expression.

http://www.regular-expressions.info/regexbuddy/dateyyyymmdd.html
0
 

Author Comment

by:R8VI
ID: 24334931
Hi, thanks for this here is the code but doesnt work i have the regular expression validator thats works so no problem just trying to get the compare validator to work first

<asp:TextBox ID="txtdate" runat="server"></asp:TextBox>
     
        <asp:CompareValidator ID="CompareValidator5" runat="server"
            ControlToCompare="txtdate" ControlToValidate="txtenddate" ErrorMessage="end date is never less than start"
            Operator="GreaterThanEqual" Type="Date"></asp:CompareValidator>
              <asp:TextBox ID="txtenddate" runat="server"></asp:TextBox>
        <asp:Label ID="lblLabeltest" runat="server" Text="End Date must not be before Start Start" Visible="false"></asp:Label>

please help,

Thanks,

R8VI
0
 
LVL 15

Accepted Solution

by:
NazoUK earned 500 total points
ID: 24335145
In this case you'd have to use a custom validator that inspects the values in the two textboxes, breaks up the numbers and works out if they are valid. You can't use a standard compare operator as you aren't actually using valid dates.
0
 

Author Comment

by:R8VI
ID: 24335248
ahhh ok kul thanks
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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