How do I validate that a correct format was entered?

I have a windows form with a textbox tbLength that displays a length of time for a scheduling program.  The user can enter a start date/time from a time picker field, and can enter a length - the combo of these 2 calculates the end date/time.  I need Length to be in a proper timespan format 1.00:00:00, etc.  How can I validate the entered value is OK?  Can I force the entered format to be 99.99:99:99?
djoyceRRDAsked:
Who is Participating?
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
you can use the TimeSpan.Parse() and TimeSpan.TryParse() static functions
0
 
planoczCommented:
Try something like this to check the format of the time...
Imports System.Text.RegularExpressions

  Function IsValidTime(ByVal strIn As String) As Boolean
        ' Return true if strIn is in valid SSN format.
        Return Regex.IsMatch(strIn, "^\d{2}:\d{2}:\d{2}$")
    End Function
0
 
djoyceRRDAuthor Commented:
Thanks!  TryParse was exactly what I was looking for.
0
All Courses

From novice to tech pro — start learning today.