|
-
Sep 12th, 2016, 07:19 PM
#15
New Member
Re: Restrict TextBox to only certain characters, numeric or symbolic
 Originally Posted by mark-totnes
I know this thread is old however I've just come across it with a Google search, so thought i'd post this if anybody else does...
I believe the simplest way to disallow characters is to use the Textbox.KeyPress event.
The below snippet handles disallowed characters AND maximum number of lines if you have a Multiline Textbox:
Code:
Private Sub txtAddress_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtAddress.KeyPress
'Below Handles Disallowed Characters
Dim DisallowedCharacters As String = "'~`{}^¨|°¬+-[]^¨"
If InStr(DisallowedCharacters, e.KeyChar) > 0 Then
e.Handled = True
End If
'Below Handles max number of lines for multiline Textbox
If txtAddress.Lines.Length >= 6 AndAlso e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
End Sub
Do you know how to update this to wear it uses 'IsNumeric'?
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
|