I have just come across a problem with the SharePoint DateTimeControl and validation. I tried using the Regular Expression validator that ASP.NET has to offer, but to no avail.
If you try and use the Regular Expression validator on these, this is what you get (apologies for the small images, click to enlarge them!):
And when you run the page the DateTimeControl is on…
After a quick Google Search, I found a couple of ways that were suggested. Some people were suggesting a ‘Read Only’ attribute, but the DateTimeControl does not support this, and will through you an equally as lovely error as the one shown above. Do not even touch this route!
However, I came across the one that has actually helped me to validate. I was a little skeptical at first but was willing to try it.
This way uses an ASP.NET CompareValidator. When you are setting the ‘ControlToValidate’ attribute, you set it as NameOfControl$NameOfControlDate. In my example, it will be dtcDate&dtcDateDate. No idea why there needs to be an extra ‘Date’ on the end, but it works so best not to argue with it!
Another recommendation I have is to add “AutoPostBack=’true'” into your DateTimeControl. Every time you add a new date, it will automatically check the fields for you before submission.
Again, I’m really sorry about the images on this blog post. Please just click the images to see them larger.
A big mention to this guy here for posting his ideas about the datetimecontrol to help me work out how to fix mine. Kudos to you!