Wildcard or Defining Characters

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.
 
B

Bob Umlas

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!)
 
D

Dennis

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top