It's better to put your allow keys in a set as a constant (speed, optimization):
Updated #2 (allowAllow only one decimal char): and handling properly DecimalSeparator.
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); const Backspace = #8; AllowKeys: set of Char = ['0'..'9', Backspace]; begin if Key = '.', Backspace]; beginthen Key := DecimalSeparator; if not ((Key in AllowKeys) or ((Key = '.'DecimalSeparator) and (Pos(Key, Edit1.Text) <>= 0)) then begin ShowMessage('Invalid key: ' + Key); Key := #0; end; end; For better results take a look at TNumericEdit components included in DevExpress, JVCL, EhLib, RxLib and many other libraries.