Notice Of Closure

Please note that this website is due to close down on 15th June 2020.

In the interim I will try to move as much content as possible over to my GitHub account. Thanks to everyone who has supported the site over the years.

» Help

How to check if a string is a number


Checking if a string is a number is quite simple, all we have to do is check if all it's characters are numbers. The situation becomes more complicated when you wish to recognize symbols ('+', '-', '$' etc.), but I'll leave that out for now. This code uses PChar as the parameter for speed reasons. If you want to send a string value to the function just typecast it.

function IsNumber(pcString: PChar): Boolean;
  Result := False;
  while pcString^ <> #0 do // 0 indicates the end of a PChar string
    if not (pcString^ in ['0'..'9']) then
  Result := True;
See an extended version of this routine – IsNumeric – in the Code Snippets Database. This routine can optionally check for floating point numbers.
Author: Unknown
Added: 2007-06-02
Last updated: 2013-10-12

« Return to contents »