[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

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...

Regards
Peter :-)
0
retep
Asked:
retep
1 Solution
 
LischkeCommented:
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
0
 
intheCommented:

like this:

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


#13 is enter key or use just [0..9]
0
 
kretzschmarCommented:
just include also the backspace

If not (Key in ['0'..'9', #13, #8]) then
     Key := #0; //reject all other keys
0
 
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 :-)
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now