Home All Groups Group Topic Archive Search About

Compare Validator for Date AND Time

Author
22 Feb 2006 4:04 PM
Chris Davoli
I am using the CompareValidator to be sure that the date is valid. I do a
DataTypeCheck with a Type of Date on the ControlToValidate. This works good
if I have just date in the Date Field, but I have Date and Time. Is there any
way to use a validator on client side to validate a field containing BOTH
Date and Time?
--

Chris Davoli

Author
23 Feb 2006 4:28 PM
Peter Blum
Hi Chris,

There is no predefined validator that handles this case. You would have to
create a custom validator to do it. If you only use server side validation,
its easy to use DateTime.Parse or ParseExact to test the string for
validity.

As the author of a popular date and time textbox (Peter's Date Package), I
have discussed the issue of merging date and time together with others. Its
my opinion that having separate date and time textboxes makes it easier both
for the user and you.
1. You can provide date specific keyboard filtering in one and time specific
in another.
2. You can offer a popup calendar on one and other tools to help enter times
on the other.
3. You can use the CompareValidator for the date text box and get client
side validation. You will have an easier time writing the client-side
validation for just handling times.

For you, its easy to split the DateTime into two strings and join them back
together on post back.
To split:
DateTime.ToShortDatePattern()
DateTime.ToShortTimePattern()
To join:
Use DateTime.Parse() on DateTextBox.Text + " " + TimeTextBox.Text

FYI: My controls include both date and time validators for my date and time
textboxes.

--- Peter Blum
www.PeterBlum.com
Email: PLB***@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

Show quoteHide quote
"Chris Davoli" <ChrisDav***@discussions.microsoft.com> wrote in message
news:4D16413A-73AF-4330-99C4-28EAF8861813@microsoft.com...
>I am using the CompareValidator to be sure that the date is valid. I do a
> DataTypeCheck with a Type of Date on the ControlToValidate. This works
> good
> if I have just date in the Date Field, but I have Date and Time. Is there
> any
> way to use a validator on client side to validate a field containing BOTH
> Date and Time?
> --
>
> Chris Davoli
>
Author
23 Feb 2006 6:43 PM
Chris Davoli
Peter, what would the client side validator look like for time? Would it be
a custom validator? What would the expression look like?

--
Chris Davoli



Show quoteHide quote
"Peter Blum" wrote:

> Hi Chris,
>
> There is no predefined validator that handles this case. You would have to
> create a custom validator to do it. If you only use server side validation,
> its easy to use DateTime.Parse or ParseExact to test the string for
> validity.
>
> As the author of a popular date and time textbox (Peter's Date Package), I
> have discussed the issue of merging date and time together with others. Its
> my opinion that having separate date and time textboxes makes it easier both
> for the user and you.
> 1. You can provide date specific keyboard filtering in one and time specific
> in another.
> 2. You can offer a popup calendar on one and other tools to help enter times
> on the other.
> 3. You can use the CompareValidator for the date text box and get client
> side validation. You will have an easier time writing the client-side
> validation for just handling times.
>
> For you, its easy to split the DateTime into two strings and join them back
> together on post back.
> To split:
> DateTime.ToShortDatePattern()
> DateTime.ToShortTimePattern()
> To join:
> Use DateTime.Parse() on DateTextBox.Text + " " + TimeTextBox.Text
>
> FYI: My controls include both date and time validators for my date and time
> textboxes.
>
> --- Peter Blum
> www.PeterBlum.com
> Email: PLB***@PeterBlum.com
> Creator of "Professional Validation And More" at
> http://www.peterblum.com/vam/home.aspx
>
> "Chris Davoli" <ChrisDav***@discussions.microsoft.com> wrote in message
> news:4D16413A-73AF-4330-99C4-28EAF8861813@microsoft.com...
> >I am using the CompareValidator to be sure that the date is valid. I do a
> > DataTypeCheck with a Type of Date on the ControlToValidate. This works
> > good
> > if I have just date in the Date Field, but I have Date and Time. Is there
> > any
> > way to use a validator on client side to validate a field containing BOTH
> > Date and Time?
> > --
> >
> > Chris Davoli
> >
>
>
>