How can i check to see if the contents of a textbox is in the valid date format?
Printable View
How can i check to see if the contents of a textbox is in the valid date format?
If IsDate(TextBox1.Text) Then
vb Code:
If IsDate(Text1.Text) Then MsgBox "Valid Date" Else MsgBox "Invalid Date" End If
Note that IsDate thinks that lots of things (such as "3/2010" and "0.13") are valid dates - while you probably don't.
Unless you have a very good reason for using a textbox, I strongly suggest you use one of the alternatives shown in the article What controls can I use to input a date/time? from our Classic VB FAQs (in the FAQ forum). If you use a Date based control like the DTP, you don't need any checking at all.