?
Solved

Validate Textbox Control between dates..please help.

Posted on 2009-05-19
16
Medium Priority
?
416 Views
Last Modified: 2012-05-07
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?
0
Comment
Question by:devnewbee
  • 8
  • 8
16 Comments
 
LVL 7

Expert Comment

by:urir10
ID: 24424498
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 )
0
 
LVL 7

Expert Comment

by:urir10
ID: 24424556
Sorry maybe this

If (DateTime.Parse(txt_startDate.Text) < DateTime.Now.AddDays(200))
0
 

Author Comment

by:devnewbee
ID: 24425302
uri,

So I could add this in the "Valueto Compare" dialog in the codebehind?
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:devnewbee
ID: 24425326
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.
0
 
LVL 7

Expert Comment

by:urir10
ID: 24425346
Oh no that code is not for the Validator that code is for the codebehind to validate on form submit or whatever
0
 

Author Comment

by:devnewbee
ID: 24425458
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;

0
 

Author Comment

by:devnewbee
ID: 24425467
This gives me the correct validation for the 200, but not for 300.
0
 
LVL 7

Expert Comment

by:urir10
ID: 24425650
are you trying to compare the same value to be less then 300 and less the 200?
0
 

Author Comment

by:devnewbee
ID: 24425691
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.
0
 
LVL 7

Expert Comment

by:urir10
ID: 24425834
if its under 45 wouldnt that be under 300 anyways?
0
 

Author Comment

by:devnewbee
ID: 24425895
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...
0
 
LVL 7

Expert Comment

by:urir10
ID: 24425920
Ok that makes more sense. So are you using a validator or validating in code?
0
 

Author Comment

by:devnewbee
ID: 24425950
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.
0
 
LVL 7

Accepted Solution

by:
urir10 earned 2000 total points
ID: 24426010
why not write in in code , i guess on the click event of the submit button:



 
If (DateTime.Parse(txt_Date.Text) > DateTime.Now.AddDays(200) 
        && DateTime.Parse(txt_Date.Text)< DateTime.Now.AddDays(300)){
//Goes here if the date is over 200 days from current date but less the 300
}
 
//Or use this 
If (DateTime.Parse(txt_Date.Text) < DateTime.Now.AddDays(200) 
        || DateTime.Parse(txt_Date.Text)> DateTime.Now.AddDays(300)){
//Goes here if the date is NOT over 200 days from current date or NOT less the 300
}

Open in new window

0
 

Author Comment

by:devnewbee
ID: 24426077
Thank you.  As always, thanks for the help.
0
 
LVL 7

Expert Comment

by:urir10
ID: 24426161
You welcome
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

850 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