Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   How To Validate A Text Box With Hh.mm (http://www.programmingforums.org/showthread.php?t=1331)

masanovic Nov 29th, 2004 10:29 AM

Hi all, Can anyone shed like on how I can validate a textbox to make sure its in the format hh.mm?

Ooble Nov 29th, 2004 1:09 PM

You could do:
:

Private Sub Text1_LostFocus()
  Dim error As Boolean
  Dim x As Integer
 
  If Len(Text1.Text) <> 5 Then
    error = True
  Else
    For x = 1 To Len(Text1.Text)
      If x <> 3 And IsDigit(Mid(Text1.Text, x, 1)) = False Then
        error = True
      ElseIf x = 3 And Mid(Text1.Text, x, 1) <> ":" Then
        error = True
      EndIf
  EndIf
 
  If error = True Then
    MsgBox "Error: please enter the data in the format HH:MM.", vbError, "Error"
  EndIf
End Sub


There's definitely a few bugs in this code and it's written for VB6, but it should give you an insight into what you need to do.


All times are GMT -5. The time now is 2:35 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC