Latest News
This following code just allowed you to entered strings / alphabetics only (no numbers or any special characters):
Posted by Gregfox
on
10/27/08
, under
(no numbers or any special characters,
This following code just allowed you to entered strings / alphabetics only (no numbers or any special characters)
|
comments (0)
- Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If (Microsoft.VisualBasic.Asc(e.KeyChar) < 65) _ Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 90) _ And (Microsoft.VisualBasic.Asc(e.KeyChar) < 97) _ Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 122) Then 'Allowed space If (Microsoft.VisualBasic.Asc(e.KeyChar) <> 32) Then e.Handled = True End If End If ' Allowed backspace If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then e.Handled = False End If End Sub
This following code just allowed you to entered numbers only (No alphabetics or any special characters
Posted by Gregfox
on , under
No alphabetics or any special characters,
This following code just allowed you to entered numbers only (No alphabetics or any special characters
|
comments (0)
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _ Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then e.Handled = True End If If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then e.Handled = False End If End Sub
To make text box to accept only numbers, in key press event of that textbox u can code like this
Posted by Gregfox
on , under
in key press event of that textbox u can code like this,
To make text box to accept only numbers
|
comments (0)
If Char.IsDigit(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
e.Handled = True
MsgBox("Please enter valid number ")
End If