Wildcard or Defining Characters

  • Thread starter Thread starter Dennis
  • Start date Start date
D

Dennis

I declare a variable 'x' that goes into a Input Box. I only want the
charachters a-zA-Z0-9 and the '/' to accepted as valid input. I gave it a 4
attempt but once again am seeking help.
 
Try:
x=INPUTBOX("....")
if OK(x) then
...
End if

Function OK(arg As String) As Boolean
OK = True
For i = 1 To Len(arg)
If Mid(arg, i, 1) Like "[A-Z]" Or Mid(arg, i, 1) Like "[a-z]" Or
Mid(arg, i, 1) Like "[0-9]" Or Mid(arg, i, 1) = "/" Then
Else
OK = False
Exit Function
End If
Next
End Function

Bob Umlas
Excel MVP

(But I think there's gotta be a shorter way!)
 
Thanks Bob!

"Bob Umlas" said:
Try:
x=INPUTBOX("....")
if OK(x) then
...
End if

Function OK(arg As String) As Boolean
OK = True
For i = 1 To Len(arg)
If Mid(arg, i, 1) Like "[A-Z]" Or Mid(arg, i, 1) Like "[a-z]" Or
Mid(arg, i, 1) Like "[0-9]" Or Mid(arg, i, 1) = "/" Then
Else
OK = False
Exit Function
End If
Next
End Function

Bob Umlas
Excel MVP

(But I think there's gotta be a shorter way!)
Dennis said:
I declare a variable 'x' that goes into a Input Box. I only want the
charachters a-zA-Z0-9 and the '/' to accepted as valid input. I gave it a 4
attempt but once again am seeking help.
 
Back
Top