Solved

compare validator asp.net, c#

Posted on 2009-05-08
7
690 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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 article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

839 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