Solved

How do I validate that a correct format was entered?

Posted on 2008-06-20
3
241 Views
Last Modified: 2010-04-23
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?
0
Comment
Question by:djoyceRRD
3 Comments
 
LVL 27

Expert Comment

by:planocz
Comment Utility
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
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 125 total points
Comment Utility
you can use the TimeSpan.Parse() and TimeSpan.TryParse() static functions
0
 

Author Closing Comment

by:djoyceRRD
Comment Utility
Thanks!  TryParse was exactly what I was looking for.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now