TEdit : auto complete and limit minimum number

delphi

Solution

A `TMaskEdit` with an `EditMask` of `000000000000;0;0` will do exactly what you want, without your having to write the code and deal with things like Del, Backspace, or LeftArrowRightArrow keys.

Problem

Here is on key press event: ``` procedure TForm3.Edt1KeyPress(Sender: TObject; var Key: Char); begin if not(Key in [#8, '0' .. '9']) then begin memo1.Clear; Print('Numbers only !'); Key := #0; end; edt1.MaxLength := 12; end; ``` So here is the story: I want to auto complete my TEdit. Every time i type on TEdit, it will auto complete my (any) numbers. Just fill it with '0' after the first number, and it will be replaced as the second number is typed... and stop on max length (was set to 12). ``` procedure TForm3.btn1Click(Sender: TObject); var key : Char; begin if Trim(edt1.Text) = '' then begin memo1.Clear; Print('Please input your number'); Exit end; // Text number CAN NOT LESS than 12 digits. I think it's better with auto-complete. end; ```

Original source