Regex OnKeyDown question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • el_squid_2000@yahoo.com

    #1

    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.SuppressKeyPr ess = false;

    if (myRegex.IsMatc h(e.KeyData.ToS tring()))
    e.SuppressKeyPr ess = 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

    #2
    Re: Regex OnKeyDown question

    el_squid_2000@y ahoo.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.SuppressKeyPr ess = false;
    >
    if (myRegex.IsMatc h(e.KeyData.ToS tring()))
    e.SuppressKeyPr ess = 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

    Comment

    Working...