Link to home
Start Free TrialLog in
Avatar of PMH4514
PMH4514

asked on

Need RegEx to validate time entry

Hi - I need two visual basic functions, using regular expressions (or a better solution if appropriate?) one to validate that a string is a valid 24H format time value, the other to validate that a string is a valid 12H format time value.  Hours and Minutes, no seconds.

Thanks
-paul
Avatar of aelatik
aelatik
Flag of Netherlands image

I don't think thats possible, If i look at '11:00' i can't determine if its a 12 or 24 hour format unless it contains an AM or PM notification.

Avatar of PMH4514
PMH4514

ASKER

ok, lets assume the existance of AM or PM on the 12H string, and no such indicator on the 24H string..
ASKER CERTIFIED SOLUTION
Avatar of trkcorp
trkcorp

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
maybe:

Function ValidateHour(sHour As String) As Boolean
If InStr(1, sHour, "AM", vbTextCompare) Or InStr(1, sHour, "PM", vbTextCompare) Then
   ValidateHour = IsDate(sHour)
End If
End Function
ups!, sorry trkcorp
Avatar of PMH4514

ASKER

using the isDate() function to test a valid time will work..  doesn't specifically answer the question asked, but the end result for me is the same..
Just like Richie posted, If there is PM or AM in time then its a 12 hour notification, otherwise 24. Or am i wrong here ?