Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[TuToRiAl] Restricting TextBox Input (Numeric Only TextBox, etc...)
#7
Not trying to discredit you, Im just sharing some knowledge. A better way to do something like this (instead of looping through the text each time) would be this.

not allowed
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim NotAllowed As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,<>./?; :'{}[]=+-_)(*&^%$#@!~`|\"
        If NotAllowed.IndexOf(e.KeyChar) <> -1 Then
            e.KeyChar = Nothing
        End If
End Sub

allowed
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim Allowed As String = "abcdefghijklmnopqrstuvwxyz@"
        If Allowed.IndexOf(e.KeyChar) = -1 Then
            e.KeyChar = Nothing
        End If
End Sub
Reply


Messages In This Thread
RE: [TuToRiAl] Restricting TextBox Input (Numeric Only TextBox, etc...) - by KoBE - 11-10-2010, 09:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to display google captcha picture on form and add to textbox hit ok to bypass polas 0 1,266 09-14-2012, 01:59 PM
Last Post: polas
  [TuToRiAl] How to make Offline (No Internet) Captcha (Human Confirmation) [TuToRiAl] Resistance 24 12,535 08-30-2012, 10:14 PM
Last Post: Resistance
  [Release] TextBox Color Changer [Release] Resistance 23 6,979 10-14-2011, 02:55 PM
Last Post: Resistance
  {TuToRiAl} How To Verify If Your App. Was Ran As Administrator {TuToRiAl} Resistance 11 6,017 10-11-2011, 04:30 PM
Last Post: Genuine
  How to set a textbox's value [VB] James Ford 10 2,207 09-01-2011, 02:15 AM
Last Post: James Ford

Forum Jump:


Users browsing this thread: 5 Guest(s)