Link to home
Start Free TrialLog in
Avatar of devnewbee
devnewbee

asked on

Validate Textbox Control between dates..please help.

How can I validate a textbox so that the entered date is no greater than 200 days out from the current date, but less than 300 days out from the current date?
Avatar of urir10
urir10

Your requirment doesnt really make sense but this is how you would do it:


if (DateTime.Parse(txt_startDate.Text).CompareTo(DateTime.Now.AddDays(200)) < 200 )
Sorry maybe this

If (DateTime.Parse(txt_startDate.Text) < DateTime.Now.AddDays(200))
Avatar of devnewbee

ASKER

uri,

So I could add this in the "Valueto Compare" dialog in the codebehind?
I am just tring to use a compare validator on the textbox.  Right now, i am using two validators, but would like to narrow it to one.
Oh no that code is not for the Validator that code is for the codebehind to validate on form submit or whatever
Is there a syntax I can use other than:

        string s45Date = DateTime.Now.AddDays(200).ToShortDateString();
        string s110Date = DateTime.Now.AddDays(300).ToShortDateString();
        cfv200ueToCompare = s200Date;
        cv300.ValueToCompare = s300Date;

This gives me the correct validation for the 200, but not for 300.
are you trying to compare the same value to be less then 300 and less the 200?
I just want to make sure the date they enter (a start date for a service) falls no greater than 300 days from the date they enter and does not fall under 45 days.
if its under 45 wouldnt that be under 300 anyways?
Oh no, sorry...the 45 is not correct, it is suppose to be 200.

I can get the 200 to work, but if I choose lessthenequal to 300, that is when I run into the issue, because that works.

So, the exact criteria for the textbox is to be greater than 200, but less than 300 days from the current date.

Hope that helps...
Ok that makes more sense. So are you using a validator or validating in code?
I was using a validator, and calling the "valuetocompare" from the codebehind.

I am open to anything that will prevent submission of a date that doesn'nt adhere to the criteria though.
ASKER CERTIFIED SOLUTION
Avatar of urir10
urir10

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.  As always, thanks for the help.
You welcome