Compare Validator for Date AND Time

Compare Validator for Date AND Time

Post by Q2hyaXMgRG » Fri, 24 Feb 2006 01:04:28


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
 
 
 

Compare Validator for Date AND Time

Post by Peter Blu » Sat, 25 Feb 2006 01:28:08

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: XXXX@XXXXX.COM
Creator of "Professional Validation And More" at
http://www.yqcomputer.com/

 
 
 

Compare Validator for Date AND Time

Post by Q2hyaXMgRG » Sat, 25 Feb 2006 03:43:57


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