.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old May 5th, 2008, 04:26 PM
Pit76 Pit76 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 3 Pit76 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 43 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old May 6th, 2008, 05:03 AM
John Adams John Adams is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 2 John Adams User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 10 m 3 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old May 6th, 2008, 09:52 AM
LyonHaert's Avatar
LyonHaert LyonHaert is offline
Arcane Scribbler
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2005
Location: Indianapolis, IN
Posts: 1,610 LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 18 h 39 m 36 sec
Reputation Power: 378
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.
Comments on this post
eclipsed4utoo agrees!
__________________
Joel B Fant - LyonHaert.net

2 + 2 is... 10... in base 4

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Keypress: allow only letters and numbers with max lenght of 5 chars


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway