Support Forums

Full Version: [Source] Allowed Characters in Textbox / Richtextbox
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The gui is derive from this forum. hehehe Yeye

[Image: oDCQl.png]

I just used simple codes and used in keypress event.
Full Codes:
Code:
Public Class Form1

    Private Sub RichTextBox1_KeyPress(ByVal sender As Object, _
                                      ByVal e As System.Windows.Forms.KeyPressEventArgs) _
                                      Handles RichTextBox1.KeyPress

        If (e.KeyChar < "a" OrElse e.KeyChar > "z") AndAlso (e.KeyChar < "A" OrElse e.KeyChar > "Z") Then
            e.Handled = True
        End If
    End Sub

    Private Sub RichTextBox2_KeyPress(ByVal sender As Object, _
                                      ByVal e As System.Windows.Forms.KeyPressEventArgs) _
                                      Handles RichTextBox2.KeyPress

        If e.KeyChar < "0" Or e.KeyChar > "9" Then
            e.Handled = True
        End If
    End Sub
End Class

Edit: Ooops I have a grammar error in the description.
You also need to allow keys like backspace to be pressed. Don't forget that...Nice gui anyway Smile
(05-16-2011, 05:26 AM)thanasis2028 Wrote: [ -> ]You also need to allow keys like backspace to be pressed. Don't forget that...Nice gui anyway Smile

Tested in Windows 7, backspace is working fine.