Trying to check date entered using validation

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!
 
C

Cristian Suazo

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
 
B

bredal Jensen

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
 
T

TN Bella

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!
 
T

TN Bella

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!
 
T

TN Bella

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top