473,504 Members | 13,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex OnKeyDown question

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

Oct 21 '07 #1
1 1980
el***********@yahoo.com wrote:
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 ...
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
Oct 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3887
by: Z | last post by:
I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a...
5
1421
by: Russell Campbell | last post by:
I was using onKeyDown to change Enter to Tab. However, in a textarea, this prevents a CRLF from being entered and just moves you to the next field. So I thought if I put an onKeyDown on the...
3
7375
by: euler | last post by:
why did the keydown event not fire in this simple example? <HTML> <HEAD><title>keydown_div</title> <script type="text/javascript"> function keydown() { alert("keydown"); } </script>
10
9128
by: b.dam | last post by:
I'm trying the following: function grid() { this._el = document.createElement("TABLE"); var self = this; document.addEventListener("onkeydown", function(event) {self.gridKeyDown(event);},...
5
2687
by: Dave Henson | last post by:
Hi I am checking a site for accessibility and Dreamweaver suggests making sure that the menu is accessible via keyboard as well as mouse (i.e device-independent). A question has arisen which is...
17
3941
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
5
3786
by: Roger Withnell | last post by:
I'm using the following code to start a function on key down. document.onkeydown = OnKeyDown; function OnKeyDown() { vKeyCode = event.keyCode; ..code... }
1
5726
eboyjr14
by: eboyjr14 | last post by:
I have this UserScript for Grease monkey. but I can't get the onleydown event to fire in FIREFOX only. I've looked everywhere! // ==UserScript== // @name iGoogle Suggest //...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.