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
Thanks
-paul
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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 ?