Library code snippets

Determine if a variable is numeric

There are a number of ways to determine if a variable in PHP is numeric. If you have PHP 4, you can use the is_numeric function:

if (is_numeric($thefield)==false) {
  echo "\$thefield is not a number";
}

If you have PHP 3, then you can use the following function

function is_numeric($value) {
  if (((int) $value)== $value) {
    return true;
  } else {
    return false;
  }
}

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of Determine if a variable is numeric.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related discussion

Related podcasts

  • Java Posse #212 - Oracle Developer Tools Interview

    Interview with Ted Farrell about Oracle Developer Tools Fully formatted shownotes can always be found at http://javaposse.com We talk to Ted Farrell (and at the end Duncan Mills) about the Oracle Java developer tools, the new Oracle 11g product stack, Oracle's work on JSRs, the future of the ...

Related jobs