RE: Determine if an input key is a number, letter or special character

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi moondaddy,

You aren't telling is what kind of input you are talking about, but the Char
class has a set of static methods for determining what type a given character
is. For instance System.Char.IsDigit(), ...IsLetter(), ...IsControl().

If you mean input keys as in KeyEvent... there is no way to determine if a
given Key is a digit, letter or special character. You have to set up a list
of keys for each type, like D0-D9 + NumPad0-NumPad9 would mean digit input.

To ignore invalid entries in a TextBox, handle the OnKeyPress event and
check the Char value. If not valid, set KeyPressEventArgs.Cancel to true.

--
Happy Coding!
Morten Wennevik [C# MVP]


"moondaddy" wrote:

Is there a simple way to determine if an input key is a number, letter or
special character? in other words, was the user inputting data and not
typing a backspace, shift, etc.

Thanks.

--
moondaddy@xxxxxxxxxxxxxxxx


.



Relevant Pages

  • Re: Determine if an input key is a number, letter or special character
    ... I was referring to the keys input as in what did the user type. ... letter or special character. ... like D0-D9 + NumPad0-NumPad9 would mean digit input. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: why use CHAR.. _EVER_?
    ... stuff like keys? ... i just dont understand why 'aaron' matches to 'aaron ' ... uses CHAR instead of VarChar. ... it is always 5 characters and you want to preserve any leading 0's. ...
    (microsoft.public.sqlserver)
  • Re: why use CHAR.. _EVER_?
    ... when they only hold data that is 10 characters long. ... stuff like keys? ... using a query where field1 = 'aaron' it finds a match; ... SQL, by definition, ignores white-space at the end of CHAR data types. ...
    (microsoft.public.sqlserver)
  • Re: sort problem
    ... AS> # Set $order{$char} to increasing values in the sequence we want ... AS> we can sort the keys in the required order. ... strings and the number of hash keys. ... generating syntax clean code with funny chars can be tricky. ...
    (comp.lang.perl.misc)
  • Re: Sort keys in a hash numerically
    ... I have a has with keys like ... Char. ... I want to iterate over the whole hash in numerical order. ...
    (comp.lang.perl.misc)