blog

Articles about web development from the consultants at sourcemotion limited.

Monday, October 27, 2008

Using the ASP.NET CompareValidator control to validate date input

Stumbled across this tip the other day:

http://dotnettipoftheday.org/tips/validate-format-of-integer-double-date-currency.aspx

It turns out that you can validate date inputs with a CompareValidator by setting the Operator property to DataTypeCheck and ValidationDataType to Date (or Integer, Double, Currency, etc.).

This was a new one on me, I had always assumed that the CompareValidator was just used for comparing the value of a control with another control (or a constant value) which is what the name (and MSDN) would suggest. I don't know why Microsoft didn't create a separate control called a DataTypeValidator with this functionality rather than hide it within the CompareValidator.

Labels: , ,

0 Comments:

Post a Comment

<< Home