how do i check if something is alpha numeric?
Printable View
how do i check if something is alpha numeric?
Code:'in declarations
option compare text
'the code
If Text like "[A-Z]" then...
what wouldm happen if it was a number?
If it's like a number than you do this:
Code:If Text Like "#" Then ...
try this function:
since it returns a boolean value, you can use it for validation. for example,Code:Public Function IsAlphaNumeric(ByVal sStr As String) As Boolean
Dim lPos As Long
Const ALPHA_NUM As String = "abcdefghijklmnopqrstuvwxyz" & _
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
lPos = StrSpn(StrPtr(sStr), StrPtr(ALPHA_NUM))
IsAlphaNumeric = (lPos = Len(sStr))
End Function
hope this helpsCode:If IsAlphaNumeric(myTextBox.text) = true Then
msgbox "valid"
End If
IsNumeric which returns a bool.
ie
not so good if its both... unless you cut it up, bit by bit. That could help.Code:Dim MyVar, MyCheck
MyVar = "53" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
MyVar = "459.95" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
MyVar = "45 Help" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns False.
thanks everyone