Solved

How do I validate that a correct format was entered?

Posted on 2008-06-20
3
267 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
ID: 21834835
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
ID: 21834860
you can use the TimeSpan.Parse() and TimeSpan.TryParse() static functions
0
 

Author Closing Comment

by:djoyceRRD
ID: 31469316
Thanks!  TryParse was exactly what I was looking for.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Modal Popup Extender control 1 38
which modules are active in VB6 project? 6 44
VB.net and sql server 4 45
Need help converting bitmap to image in VB.Net 8 30
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

828 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