Skip to content

Instantly share code, notes, and snippets.

Created May 19, 2017 23:43
What would you like to do?
Pros/Cons of is_numeric()


is_numeric() is a conditional that tests if the value passed is numeric and returns false if not.


  • Does not do any sanitization of the input value
  • Will return true for values that could never or would never be a ID of a WordPress core object such as decimals (see truthy values below).
  • WordPress does not consistently create false cases for testing the results of any is_numeric condition tests thus no feedback upon failure.

Values is_numeric() considered valid:

  • +0123.45e6
  • 12.3456
  • 12345


  1. is_numeric allows for the creation of a false condition whereby the function testing the condition could be notified of a false condition and adjust accordingly.
  2. Since is_numeric is a function, it can be passed to a function as a parameter that accepts functions such as array_map(‘is_numeric’, $array) for validation purposes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment