DELPHI 中如何让edit1.text只能输入数字和字母

如题,我DELPHI新手,能有一种比较简单的方法吗
2025-04-18 04:30:31
推荐回答(3个)
回答1:

在keypress里面设定
if Not (key in ['0'..'9', #8, '.',['A'..'Z']]) then
key := #0;
这样就可以了,就是限制键盘输入其他的东西。

回答2:

procedure Tform.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Not (key in ['0'..'9', #8, '.',['A'..'Z']]) then
key := #0;
end;
这就是你想要的。

回答3:

在KeyPress事件中写入下边的代码
XE下:
if not CharInSet(Key,['0'..'9','a'..'z']) then Key :=#0;

D7下:
if not (Key in ['0'..'9','a'..'z']) then key :=#0;