Link to home
Start Free TrialLog in
Avatar of djoyceRRD
djoyceRRDFlag for United States of America

asked on

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?
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of djoyceRRD

ASKER

Thanks!  TryParse was exactly what I was looking for.