Textbox Numeric only

G

Guest

Am I crazy - to be shocked that there is no Numeric, Alpha, and AlphaNumeric Property in on the Textbox control

I searched and searched - and found other people's code - but they don't work perfectly. Some do only allow numeric - but you cannot backspace. Maybe that is "good enough" - but surely it is not that difficult to have a textbox that only accepts numeric values and backspaces.
 
B

Bernie Yaeger

Hi Keith,

I've developed a textbox that's numeric only, that allows backspacing also.
In addtion, it provides for extensions to the leave and keypress events
inside the form that's calling it so that you can force a '0' into the
textbox if it is left blank, and other such activities. I've also created
one that will allow currency - thus, 2 decimal places, but no more and
nothing after the decimal place. Both controls also allow a minus sign but
only as the first character, as it should be.

I'm sure they're not perfect controls but they've been working very nicely
for me. If you would like to see the code, let me know what you need and
I'll try to provide something useful, and let me know where to download it.

HTH,

Bernie Yaeger

Keith said:
Am I crazy - to be shocked that there is no Numeric, Alpha, and
AlphaNumeric Property in on the Textbox control?
I searched and searched - and found other people's code - but they don't
work perfectly. Some do only allow numeric - but you cannot backspace.
Maybe that is "good enough" - but surely it is not that difficult to have a
textbox that only accepts numeric values and backspaces.
 
N

n.b.k

Thats what the validator objects are for silly

Keith said:
Am I crazy - to be shocked that there is no Numeric, Alpha, and
AlphaNumeric Property in on the Textbox control?
I searched and searched - and found other people's code - but they don't
work perfectly. Some do only allow numeric - but you cannot backspace.
Maybe that is "good enough" - but surely it is not that difficult to have a
textbox that only accepts numeric values and backspaces.
 
C

Cor Ligthert

Hi Keith,

Are you only sending messages or are you also reading the answers, you have
asked this question before with not one answer why the answers did not fit.

You have at least 2 good answers on your question in that thread.

Cor
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?S2VpdGg=?= said:
Am I crazy - to be shocked that there is no Numeric, Alpha, and AlphaNumeric Property in on the Textbox control?

I searched and searched - and found other people's code - but they
don't work perfectly. Some do only allow numeric - but you cannot
backspace. Maybe that is "good enough" - but surely it is not that
difficult to have a textbox that only accepts numeric values and
backspaces.

I would allow the user to enter /everything/ he/she wants to enter. In
the textbox's validating event, I would validate input and show an
errorprovider if the input is not valid.
 
C

Cor Ligthert

This started in the thread we have that long discussion in which is now on
2E100

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
This started in the thread we have that long discussion in which is now on
2E100

In my newsreader, that's a new thread ("Textbox Numeric Only").
 
B

Bernie Yaeger

Hi Herfried,

I agree with you almost always, but not this time. Simply using the
validation events is fine, but it's inelegant - a user should be guided as
much as possible regarding what they can and can't enter. Besides, there
isn't an app that doesn't use numeric only time and again; why not build the
control to deal with this once, and use it repeatedly?

Bernie
 
H

Herfried K. Wagner [MVP]

* "Bernie Yaeger said:
I agree with you almost always, but not this time. Simply using the
validation events is fine, but it's inelegant - a user should be guided as
much as possible regarding what they can and can't enter. Besides, there
isn't an app that doesn't use numeric only time and again; why not build the
control to deal with this once, and use it repeatedly?

See:

<URL:http://groups.google.de/[email protected]>
 
C

Chris Dunaway

I agree with you almost always, but not this time. Simply using the
validation events is fine, but it's inelegant - a user should be guided as
much as possible regarding what they can and can't enter. Besides, there
isn't an app that doesn't use numeric only time and again; why not build the
control to deal with this once, and use it repeatedly?

Check out the textbox contron in the VB.Net resource kit. It allow for
these types of things.

It's also free.
 
G

Guest

Thank you Bernie. I would very much like to see the code.
Can I download it?

thank you,
Keith

----- Bernie Yaeger wrote: -----

Hi Keith,

I've developed a textbox that's numeric only, that allows backspacing also.
In addtion, it provides for extensions to the leave and keypress events
inside the form that's calling it so that you can force a '0' into the
textbox if it is left blank, and other such activities. I've also created
one that will allow currency - thus, 2 decimal places, but no more and
nothing after the decimal place. Both controls also allow a minus sign but
only as the first character, as it should be.

I'm sure they're not perfect controls but they've been working very nicely
for me. If you would like to see the code, let me know what you need and
I'll try to provide something useful, and let me know where to download it.

HTH,

Bernie Yaeger

Keith said:
Am I crazy - to be shocked that there is no Numeric, Alpha, and
AlphaNumeric Property in on the Textbox control?work perfectly. Some do only allow numeric - but you cannot backspace.
Maybe that is "good enough" - but surely it is not that difficult to have a
textbox that only accepts numeric values and backspaces.
 
B

Bernie Yaeger

Still disagree - pasting into a textbox doesn't happen 1% as often as simply
keying in.

Bernie
 
H

Herfried K. Wagner [MVP]

* "Bernie Yaeger said:
Still disagree - pasting into a textbox doesn't happen 1% as often as simply
keying in.

For me, it happens often. I am working a lot with scientific software.
For example, I copy a value in international floating point format
("1.234") and paste it into a textbox that expects local format (for
de-DE machines that's "1,234"). If in-place editing doesn't work, I
will have to start Notepad or try to remember the number, or move around
windows to be able to see the number I want to enter.

Another sample is a textbox that expects a setial number consisting of
clocks of numbers/characters separated through "-". If I have a textfile
containing the number separated through " ", then pasting won't work.

There are many other samples, most of them about pasting data that is
not in the same locale as the system, for example, date strings. I
always /hate/ Word's textboxes that pop up when entering a wrong number
("This is not a whole number."). That's really annoying.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top