1.11M Members

validation of textbox

 
0
 

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

 
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
 

Thanks experts
it is useful thread for me.

 
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
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article