onPress if Key in ['a'..'z','A'..'Z'] then Key := #0;
在keypress中增加: if not ((key >= '0') and (key <= '9')) then if ((key <> '.') and (key <> #8)) or ((key = '.') and (pos('.', Trim(Edit1.text)) > 0)) then key := #0;
上边是不允许有字母的,嘻嘻,但是 '.','/'...还是可以的;//你的要求嘛; if Not (key in ['0'..'9',#13,#8,#46 ]) then begin Key := #0; Exit; end; //这儿是只许字的,嘻嘻;
if Key in ['a'..'z','A'..'Z'] then
Key := #0;
if ((key <> '.') and (key <> #8)) or
((key = '.') and (pos('.', Trim(Edit1.text)) > 0)) then
key := #0;
if Not (key in ['0'..'9',#13,#8,#46 ]) then
begin
Key := #0;
Exit;
end;
//这儿是只许字的,嘻嘻;
如果为字母则提示或直接取消本次按键
在OnKeyPress 中
if not (Key in ['0'..'9']) and (word(Key) <> vk_back) then
Key := #0;这样也可以使用户的BackSpace键和Delete键好使,最后加个空的PopupMenu给这个编辑框,禁止粘贴进非法字符