|
-
May 21st, 2026, 04:17 AM
#4
Thread Starter
Hyperactive Member
Re: The user should be allowed to enter only these 3 numbers,1, 2, or 3, in a textbox
 Originally Posted by .paul.
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim validChars() As Char = {"1"c, "2"c, "3"c}
e.Handled = Not (validChars.Contains(e.KeyChar) OrElse Char.IsControl(e.KeyChar))
End Sub
Thanks for your kind support. Actually, I forgot to mention one thing that the user should enter any single character in that textbox (Ex: 1 or 2 or 3) not 2 characters like 12, 13, 31 etc.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|