Código Delphi
[-]
function EsNumero(cValue: string):Boolean;
var i,Estado:Byte;
begin
if Length(cValue)>0 then
Estado:=1
else
Estado:=0;
i:=1;
while (i<=Length(cValue))and(Estado<>0) do
begin
case Estado of
1:case cValue[i] of
'0'..'9':Estado:=2;
'-':Estado:=3;
else Estado:=0;
end;
2:case cValue[i] of
'0'..'9':Estado:=2;
'.':Estado:=4;
'-':Estado:=0;
else Estado:=0;
end;
3:case cValue[i] of
'0'..'9':Estado:=2;
else Estado:=0;
end;
4:case cValue[i] of
'0'..'9':Estado:=5;
else Estado:=0;
end;
5:case cValue[i] of
'0'..'9':Estado:=5;
else Estado:=0;
end;
end;
Inc(i)
end;
Result:=(Estado in [2,5])
end;
Con un Autómata
Código Delphi
[-]
procedure TForm1.Button1Click(Sender: TObject);
begin
if EsNumero(edit1.Text) then
ShowMessage('si')
else
ShowMessage('no')
end;
Así se llamaría, si no me equivoco...... funciona en todos los casos.