
Originally Posted by
Vita
Would that work?!
Of course! You can check it!
But, this version I think is better:
Code:
Function IsTicketNum(strIn As String) As Boolean
strIn = Replace(strIn, "-", "")
strIn = Format(strIn, "######-##-###")
IsTicketNum = (strIn Like "######-##-###")
End Function
Put it in a standard code module and try in the immediate window. Below are some tests that I've done:
Code:
?IsTicketNum("0123123-12-123")
True
?IsTicketNum("012-312-312-123")
True
?IsTicketNum("12312-312-123")
True
?IsTicketNum("12312-312123")
True
?IsTicketNum("0123123-12-123")
True
?IsTicketNum("000012312312123")
True
?IsTicketNum("1000012312312123")
False
?IsTicketNum("A12312312123")
False
?IsTicketNum("123")
False
?IsTicketNum("123-ABC")
False
?IsTicketNum("ABCEFGHIJKL")
False
Also, you can check it in a subroutine:
Code:
Sub TestTicket()
Dim strIn As String
strIn = InputBox("Input your ticket number", "Ticket check")
If IsTicketNum(strIn) Then
'Now strIn is in ######-##-### format.
MsgBox "'" & strIn & "' is a valid ticket num!", vbInformation, "Ticket test"
Else
MsgBox "'" & strIn & "' is not a valid ticket num!", vbExclamation, "Ticket test"
End If
End Sub
Cheers,
John