|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
Keypress: allow only letters and numbers with max lenght of 5 chars
Hi all,
Been messing around with the keypress event. I have a textbox wich only may accept 0 to 9 and every letter of the alphabet. The max chars entered in the textbox may only be 5 and backspace must be allowed.. I had tried severall things but no succes.. Only IsLetterOrDigit I can do but I am stuck with the max length.. Can anyone help me or lead the way? grts, Pit76 |
|
#2
|
|||
|
|||
|
Hi,
use the mentioned below code: Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown Me.TextBox1.MaxLength = 5 If Not e.KeyData = Keys.Back Then If Not Char.IsLetterOrDigit(ChrW(e.KeyCode)) Then e.Handled = True End If End If End Sub Hope this helps. Regards, JA ComponentOne LLC. |
|
#3
|
||||
|
||||
|
There is no need to set the TextBox's MaxLength property repeatedly in a KeyDown EventHandler. Just set it in the Properties Panel once and be done.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > Keypress: allow only letters and numbers with max lenght of 5 chars |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|