在Edit的OnKeyPress事件里限制输入,在提交时用TryStrToFloat判断procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not (Key in ['0'..'9','.',#8]) then Key:=#0; end;procedure TForm1.Button1Click(Sender: TObject); var a:Extended; begin if TryStrToFloat(Edit1.Text,a) then ShowMessage('合法') else ShowMessage('不合法'); end;
begin
if not (Key in ['0'..'9','.',#8]) then Key:=#0;
end;procedure TForm1.Button1Click(Sender: TObject);
var a:Extended;
begin
if TryStrToFloat(Edit1.Text,a) then
ShowMessage('合法')
else ShowMessage('不合法');
end;
使用格式化文本框控件TMaskEdit......