EditBox filter.

An easy way to make sure that the user only enters a key between '0..9', which means I only want the editbox to be able to contain numbers...

Peter :-)
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.

Hi Peter,

you have at least two options to try out. One is to use TMaskEdit with a proper mask to only accept numbers and the other is to intercept all keypresses to a normal TEdit and reject/ignore them if they aren't numbers.

The first solution is much easier and I'd suggest that you start working with TMaskEdit.

Ciao, Mike

like this:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
 If not (Key in ['0'..'9', #13]) then
     Key := #0; //reject all other keys

#13 is enter key or use just [0..9]

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
just include also the backspace

If not (Key in ['0'..'9', #13, #8]) then
     Key := #0; //reject all other keys
retepAuthor Commented:
Just what I was looking for. Since my question was ment for TEdit, I have choosen to accept this particular answer.

But thanks to you all!

Peter :-)
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

From novice to tech pro — start learning today.