Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

Regex OnKeyDown question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
el_squid_2000@yahoo.com - 21 Oct 2007 19:00 GMT
Hi - I have a regex defined as [^A-Z0-9] and I am trying to allow only
uppercase alphanumeric input in a textbox. So I have Uppercasing set
to true elsewhere in the program and I have an OnKeyDown event handler
with

e.SuppressKeyPress = false;

if (myRegex.IsMatch(e.KeyData.ToString()))
                   e.SuppressKeyPress = true;

Problem is shift key is being matched in the regex so shiftkey + any
alpha key is being rejected.
Any help appreciated ...

Thanks in advance,
El Squid
Peter Duniho - 21 Oct 2007 19:26 GMT
> Hi - I have a regex defined as [^A-Z0-9] and I am trying to allow only
> uppercase alphanumeric input in a textbox. So I have Uppercasing set
[quoted text clipped - 9 lines]
> alpha key is being rejected.
> Any help appreciated ...

Unless you specifically care about the exact key on the keyboard that
was pressed, you should be using the OnKeyPressed method instead of
OnKeyDown.

Note that _neither_ method is an event handler.  A minor quibble in this
context, but the difference is important.

Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.