Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

isalpha? 2

Status
Not open for further replies.

savok

Technical User
Jan 11, 2001
303
AT
i know you use isNumeric to check if its a number but what do I use to check if everything entered in the text box is alpha?

thanks
 
Check The Type Of Character

Easily check if character is upper case, lower case, alpha or numeric using API.

Preparations
Add 1 Text Box to your form.

Module Code
Declare Function IsCharUpper Lib "user32" Alias "IsCharUpperA" _
(ByVal cChar As Byte) As Long
Declare Function IsCharLower Lib "user32" Alias "IsCharLowerA" _
(ByVal cChar As Byte) As Long
Declare Function IsCharAlpha Lib "user32" Alias "IsCharAlphaA" _
(ByVal cChar As Byte) As Long
Declare Function IsCharAlphaNumeric Lib "user32" Alias _
"IsCharAlphaNumericA" (ByVal cChar As Byte) As Long

Form Code
Private Sub Text1_KeyPress(KeyAscii As Integer)
'1 - True, 0 - False
MsgBox "Upper Case: " & IsCharUpper(KeyAscii) & _
" Lower Case: " & IsCharLower(KeyAscii) & _
" Alpha: " & IsCharAlpha(KeyAscii) & _
" Alpha or Numeric: " & IsCharAlphaNumeric(KeyAscii)
End Sub

Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
Code:
Public Function IsAlpha(strW as string) as boolean
    IsAlpha = True
    For I = 1 To Len(strW)
        If Not (Mid(strW,I,1) Like "[a-zA-Z]") then
            IsAlpha = false
            exit for
        end if
    Next
End Function
 
Code:
Sub Textbox1_KeyPress (keyascii as integer)
    If KeyAscii = 8 then exit function ' Backspace
    If Not(Chr(KeyAscii) Like "[a-zA-Z]") Then keyascii = 0 
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top