Oh boy! That suggestion actually is much harder than using a validator.
Use the RangeValidator. It ignores blank fields automatically. It only
checks for errors when there is some text. Set Type=Date and your minimum
and maximum dates in the Minimum and Maximum properties.
Note that this will not report an error if the date entered is an illegal
format.
For that, use CompareValidator, Operator=DataTypeCheck, Type=Date.
Here are several ways to enhance your user interface:
1. You can combine the logic of several validators into one using the
MultiConditionValidator, part of my Professional Validation And More
product. (
http://www.peterblum.com/vam/home.aspx) It includes 22 validators
and greatly expands what you can do with validators. You can learn about the
limitations of Microsofts validators here:
http://www.peterblum.com/vam/valmain.aspx to use as you design your site.
2. There are many really nice date textboxes with popup calendars available
from third parties. They are listed at the
www.asp.net Control Gallery,
www.123aspx.com, and
www.411asp.net. Mine is Peter's Date Package
(
http://www.peterblum.com/datecontrols/home.aspx). It includes validators,
time entry, and stand-alone calendar that doesn't require post backs.
--- Peter Blum
www.PeterBlum.com
Email:
PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"Fraggle" <Fr************@yahoo.com> wrote in message
news:ce**************************@posting.google.c om...
"Richard K Bethell" <so*****@spammingisevil.bad> wrote in message
news:<OW*************@tk2msftngp13.phx.gbl>...
"Fraggle" <Fr************@yahoo.com> wrote in message
news:ce*************************@posting.google.co m... Hi,
I want to validate a text box, The user can leave it blank, or fill it
in. If they fill it in then it must be a date within a certain range.
How can I achieve this?
I'd do that as a server side validation... you don't even need the
validator for that. Throw a label in the area you want the error message to
appear. Write a boolean function that returns true if the text box is blank, or
if not, parses with DateTime.Parse to a date within your range. Then call
the function from your submit button's event
R.
Thanks.
Maybe one day I will actually do something simple enough that uses the
more "advanced" features of the .net framework, rather than having to
custom write EVERYTHING!