Numeric Edit Box Entry

I am using windows XP and borland C++ builder 6.0

I have created a form which has many edit boxes what I want to do is stop the user entering values that are non-numeric.  

Do edit boxes in c++ builder have any properties to stop the user doing this?

Appreciate any help
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


You can use the MaskEdit Control, where you have a property to define a mask

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
George TokasCommented:
Or use OnChange event handler and check as:
if(Edit1->Text.ToIntDef(-1) > -1).....
if the text contains a letter then the value will be -1...

George Tokas.
lisa_mcAuthor Commented:
Thanks for the replies.

Swissknife - I have looked into these methods im just not sure how to use them could you explain?

gtokas - When the user clicks in the edit box he can enter number values I have to ensure no letters are entered but when the user presses X the program should then do something else.  Due to this I have to write all my code in the Edit1KeyPress method checking if the keypressed is X.  I wanted to do it in a way that if the user was typing into the edit box and the value wasnt an X or 1-9 then the program wouldnt do anything.  Originally I just removed all non numeric characters from the edit box entry but when the user pressed X this letter and any others typed into the edit box was still visible in the edit box which I dont want.

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

George TokasCommented:
Use the same as I proposed at OnKeyDown and just delete the last character using:
Edit1->Text = Edit1->Text.SetLength(Edit1->Text.Length()-1) ;
Also before that you have to clear empty spaces (Not that you will have a problem using ToIntDef):
Edit1->Text = Edit1->Text.Trim();

George Tokas.
lisa_mcAuthor Commented:

when I use this on the keydown method it only lets me enter one numeric value at a time and as many non- numeric characters as I want.  I really dont know what is happening plus the user could enter letters at any position in the edit box not necessarily the last position.
lisa_mcAuthor Commented:
Eventually got code working using a MaskEdit Control thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.