How to find if a text is in Time format

  • Thread starter Thread starter Tor Inge Rislaa
  • Start date Start date
T

Tor Inge Rislaa

I have a form with a textbox where the user can type a time in the format
hh:mm (e.g. 01:00)

How can I control that the .Text is a valid Short Time format

T.I.Rislaa
 
or...

1. Create a mask routine via javascript (If this is being used in
asp.net)

2. Find a control that does masking.
 
* "Tor Inge Rislaa said:
I have a form with a textbox where the user can type a time in the format
hh:mm (e.g. 01:00)

How can I control that the .Text is a valid Short Time format

'DateTime.Parse' and/or 'DateTime.ParseExact' + 'Try...Catch'.
 
Hi Herfried,

In trying to experiment with this to perhaps find an answer and learn a bit
myself, I did find DateTime.Parse and ParseExact. However it wasn't clear
to me how to verify that the input pattern consisted of time only and of
the form "hh:mm" specifically, so as to disallow other forms such as "1 am"
or other valid times that didn't follow the hh:mm pattern.

Do you have an example that might help us?

Regards,
Ot
 
* "Ot said:
In trying to experiment with this to perhaps find an answer and learn a bit
myself, I did find DateTime.Parse and ParseExact. However it wasn't clear
to me how to verify that the input pattern consisted of time only and of
the form "hh:mm" specifically, so as to disallow other forms such as "1 am"
or other valid times that didn't follow the hh:mm pattern.

\\\
Try
Dim d As DateTime = DateTime.ParseExact("11:22", "hh:mm", Nothing)
MsgBox("Success")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
Dim d As DateTime = DateTime.ParseExact("11/22", "hh:mm", Nothing)
MsgBox("Success")
Catch ex As Exception
MsgBox(ex.Message)
End Try
///
 
Aha! There wasn't an override just providing two strings. It never
occurred to me to provide "Nothing" there.

Thank you!
 
Back
Top