3

As a (sorta) follow on from the following question - CustomValidator time c#.net - I would like to know if it is possible to use the CompareValidator to validate a time in a ASP.NET textbox?

I have attempted the following

<asp:CompareValidator ID="CompareValidator2" Operator="DataTypeCheck" 
ControlToValidate="txtTime" runat="server" ErrorMessage="* Valid time is required"      
Type="Date" Display="Dynamic" ForeColor="Red"></asp:CompareValidator>

I assumed this would work since DateTime supports (obviously) both date and times but the validator continues to fail validation with valid inputs.

So, is it possible to validate time using the CompareValidator or is a RegularExpression or Custom Validator required?

Community
  • 1
  • 1
Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243
  • i think you can use the Regular Expression. may this will hep you http://regexlib.com/DisplayPatterns.aspx?cattabindex=4&categoryId=5 – Basbous Jul 31 '11 at 13:40

2 Answers2

3

This looks like a duplicate post as seen here.

The anser was from the post was.

"This appearently cannot be done.

For the record; I used a custom validator..."

Community
  • 1
  • 1
Jethro
  • 5,896
  • 3
  • 23
  • 24
0

According to reflector, when CompareValidator validates input, he is trying to match input with reg exp like this

^\s*(\d{1,2})([-/]|\. ?)(\d{1,2})(?:\s|\2)((\d{4})|(\d{2}))(?:\sг\.|\.)?\s*$

That's why if you pass only time CompareValidator always returns false.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Nastya Kholodova
  • 1,301
  • 9
  • 18