请教怎么限制用户在edit文本框内只能输入数字或小数
请问如何限制用户在edit文本框内只能输入数字或小数?
请问如何限制用户在edit文本框内只能输入数字或小数?
或者如何判断出用户在edit文本框中输入的不是数字或小数?
(例如只能输入15,12.36等等)
谢谢。
------解决方案--------------------
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Not(Key in [ '0 '.. '9 ', '. ']) then Key := #0;
end;
------解决方案--------------------
procedure TForm32.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in [ '0 '.. '9 ', '. ' ,#8,#13]) then
key := #0 ;
if (key = #13) and (trim(edit3.Text) <> ' ') then
begin
if (form32.ComboBox2.ItemIndex = 5) or (form32.ComboBox2.ItemIndex = 6) then
begin
Form32.Edit5.SetFocus ;
Form32.Edit5.SelectAll ;
end
else
begin
Form32.Edit4.SetFocus ;
Form32.Edit4.SelectAll ;
end ;
end ;
end;
请问如何限制用户在edit文本框内只能输入数字或小数?
或者如何判断出用户在edit文本框中输入的不是数字或小数?
(例如只能输入15,12.36等等)
谢谢。
------解决方案--------------------
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Not(Key in [ '0 '.. '9 ', '. ']) then Key := #0;
end;
------解决方案--------------------
procedure TForm32.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in [ '0 '.. '9 ', '. ' ,#8,#13]) then
key := #0 ;
if (key = #13) and (trim(edit3.Text) <> ' ') then
begin
if (form32.ComboBox2.ItemIndex = 5) or (form32.ComboBox2.ItemIndex = 6) then
begin
Form32.Edit5.SetFocus ;
Form32.Edit5.SelectAll ;
end
else
begin
Form32.Edit4.SetFocus ;
Form32.Edit4.SelectAll ;
end ;
end ;
end;