Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining numeric data 2

Status
Not open for further replies.

Jonah86

Programmer
Dec 11, 2003
152
US
Is there any way to determine weather or not the text in an edit box is numeric or not. I remember a little form VB that was something like "if not isnumeric" and you could use that to validate data pretty well. Just wondering if there is a simillar function in Delphi.

thanks.
 
If you just want your users to put in numeric data you can use the TSpinEdit on the Samples page, it's marvelous, you can set the minimum number the maximum number the steps in between and you can retrieve the value either as an integer or as text as well. This component won't allow non-numerical input.

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
You do not specify if you want cardinals (zero and positive whole numbers), integers (zero, positive and negative whole numbers) or real numbers ( digits before and after a decimal point).

You may find the following functions useful which will test a string (e.g. Edit1.Text) for being a Cardinal, Integer or a Real.

Code:
function IsCardinal ( value: string ): boolean;
begin
  result := StrToIntDef ( value, -1 ) >= 0;
end;

function IsInteger ( value: string ): boolean;
var
  code: integer;
  temp: integer;
begin
  Val ( value, temp, code );
  result := code = 0;
end;

function IsReal ( value: string ): boolean;
var
  code: integer;
  temp: Single;
begin
  Val ( value, temp, code );
  result := code = 0;
end;

Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top