Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I validate that a correct format was entered?

Posted on 2008-06-20
3
Medium Priority
?
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

705 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