0

VB .Net : how to validate textbox to get only alphabets a-z , A-Z...Pls help me

Edited by warne: n/a

5
Contributors
7
Replies
13
Views
6 Years
Discussion Span
Last Post by Netcode
1

to valid textboxes write the code in keypress event
like

private sub textbox1_keypress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles  textbox1.KeyPress
Dim KeyAscii As Integer
        KeyAscii = Asc(e.KeyChar)
        Select Case KeyAscii
case 65 to 90 ''for capital ALPHABET A
case 97 to122
case else
keyascii=0
End Select

        If KeyAscii = 0 Then
            e.Handled = True
            MessageBox.Show("Please Type Word  only", "Type the Numbers!", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
            e.Handled = False
        End If

end sub

it's simple
try it will run

0

thank you..it is working as i expected...But when i press backspace or delete key, it is showing the messagebox. I want this textbox to accept backspace and delete key also..please help me...

0

then add the KEYASCII value of enter and backspace
that is

case 13 
 case 8

in that code it will run if your problem is solved mark thread as a solve .

0

The Below Code validation for Text,Numeric values and symbols are not allowed.

If Char.IsPunctuation(e.KeyChar) = True And Asc(e.KeyChar) <> 8 Then
            e.Handled = True
            MsgBox("Please Enter only letter.")
ElseIf Char.IsNumber(e.KeyChar) = True And Asc(e.KeyChar) <> 8 Then
            e.Handled = True
            MsgBox("Please Enter only letter.")
End If

For Symbol and Text

If Char.IsNumber(e.KeyChar) = True And Asc(e.KeyChar) <> 8 Then
            e.Handled = True
            MsgBox("Please Enter only letter.")
End If
0

Code For allowing Numbers only:

If (Char.IsPunctuation(e.KeyChar) = True Or Char.IsLetter(e.KeyChar) = True) And   Asc(e.KeyChar) <> 8 Then
            e.Handled = True
            MsgBox("Enter Numbers Only")
        End If
0
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        If Not IsNumeric(.Text) Then
            MessageBox.Show("please enter a valid string", "Error" _
                             , MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.