如果只输入数字用wzg1031(0223)的就可以
如果想只输入数值用这个(虽然烦琐点,但很好用,可以输入负号,限制小数位数
在EDIT的ONKEYPRESS事件调用,如限制EDIT1,2位小数就:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
mykeypress(edit1,2,key);
end;);
procedure MyKeyPress(MyKess: TEdit; Len: integer; var Key: char);
begin
if MyKess.SelLength =length(MyKess.Text) then
MyKess.Clear;
if (Key <> '1') and (Key <> '2') and (Key <> '3') and (Key <> '4') and (Key <>
'5') and (Key <> '6') and (Key <> '7') and (Key <> '8') and (Key <> '9') and
(Key <> '0') and (Key <> '.') and (Key <> '-') then
begin
if Key <> #8 then
Key := char(0);
end
else
begin
if Key = '.' then
begin
if pos('.', MyKess.Text) <> 0 then
Key := char(0)
end
else
if Key = '-' then
begin
if trim(MyKess.Text)<>'' then
Key := char(0)
end
else
begin
if (pos('.', MyKess.Text) <> 0) and (Length(copy(MyKess.Text, pos('.',
MyKess.Text) + 1, Length(MyKess.Text))) > Len - 1) then
Key := char(0)
else
if (trim(MyKess.text)='0') or (trim(MyKess.text)='-0') then
Key := char(0);
end;
end;
end;