Trying to check date entered using validation

  • Thread starter Thread starter TN Bella
  • Start date Start date
T

TN Bella

Trying to check if an entry for an date is < 3 years to current date or
30 days from current date. How can I do this in asp.net....? Do I need
to use the customvalidation. Can anyone give me an example? Thanks in
advance for the help

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Hi,

here you have a code snippet:



<asp:TextBox ID="txt" Runat=server></asp:TextBox>
<asp:RangeValidator ID="validDate" Type=Date MinimumValue="2004-10-10"
MaximumValue="2004-10-11" ControlToValidate="txt" EnableClientScript="true"
ErrorMessage="invalid date" Runat=server Display=Dynamic />
<asp:ValidationSummary Runat=server
EnableClientScript=True></asp:ValidationSummary>
<asp:Button Runat=server ></asp:Button>


Now the dates a set static but to change this to make them dynamic add
something like this to the script section of your code:

validDate.MinimumValue = Now.AddYears(-3)
validDateMaximumValue = Now.AddDays(30)

I haven't tested all of this now but the concepts are these...
Bye
Cristian
 
Well that looks good, but can it be globalized?

Date format seem to vary with cultures. So i doubt the hardcoded date format
will
hold when the application should support other cultures.

But you are totally right if globalization is not an issue for the
given product.

Thanks

J.B
 
Wait...I can't use a variable instead so the date doesn't have to be
updated each time in the maximum and minimum value?



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Thanks a bunch..>I am going to test it right now. And no, I don't need
to worry about globalization. I appreciate the input. Thanks again!



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Okay...Thanks Cristian...I just needed to wake up. Thanks a lot for the
help! Here is what was changed:

Private Sub Page_Load
validDate.MinimumValue =
CDate(DateTime.Now.AddYears(-3).ToShortDateString)
validDate.MaximumValue =
CDate(DateTime.Now.AddDays(30).ToShortDateString)
End Sub

Have a great day!


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Back
Top