Author Topic: Function is_numeric()  (Read 1837 times)

0 Members and 1 Guest are viewing this topic.

Offline Railor

  • Major(1)
  • Posts: 16
Function is_numeric()
« on: February 04, 2008, 06:11:13 am »
Script Name: is_numeric
Script Description: Very simple script. Finds whether the given variable is numeric. Returns TRUE if 'oo' is a number or a numeric string, FALSE otherwise.
Original Author(s): Railor
Core Version: 2.6.3
Code:
Code: [Select]
function is_numeric(oo: string): boolean;
begin
if GetURL('http://example.com/numeric.php?n=' + oo)  // replace the URL with the position of the PHP Script
                 = '1' then
begin
Result := true
end else
begin
Result := false
end
end;
Important! You have to turn the safe mode off!

PHP Script:
Code: [Select]
<?php
if(is_numeric($_GET['n'])) 
{
echo '1';
}
else
{
echo '0';
}
?>

« Last Edit: February 04, 2008, 06:14:51 am by Railor »

Offline sai`ke

  • Camper
  • ***
  • Posts: 318
  • Can't be arsed to remove christmas avatar
Re: Function is_numeric()
« Reply #1 on: February 04, 2008, 06:28:13 am »
This sounds like a very nasty work around someone might need to make up for bad coding habits. You'd probably be better off just assuming it's numeric and use try and except to deal with the cases when it's not.
#soldat.ttw #ttw.gather --- Quakenet!
http://ttwforums.com

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: Function is_numeric()
« Reply #2 on: February 04, 2008, 08:37:55 am »
Topic hijack!

Code: [Select]
function is_numeric(const source: string):boolean;
begin
try
strtoint(source);
result := true;
except
result:=false;
end;
end;

Checks for an integer, so if you want floating point numbers as well just change strtoint into strtofloat.

Offline Railor

  • Major(1)
  • Posts: 16
Re: Function is_numeric()
« Reply #3 on: February 04, 2008, 12:10:36 pm »
Topic hijack!

Code: [Select]
function is_numeric(const source: string):boolean;
begin
try
strtoint(source);
result := true;
except
result:=false;
end;
end;

Checks for an integer, so if you want floating point numbers as well just change strtoint into strtofloat.

That way i tried it first, but for some reason it don´t work, so i made it with PHP ...