You need to test a string to see if it is a valid numeric value.
The isNumeric() function is used to directly test a variable to see if it is numeric.
A Boolean response (True or False) is returned.
The val() function on the other hand, will go beyond an all or nothing check. It will attempt to parse out a number from the beginning of a string, and return this number if it exists:
If the beginning of the string contains a number, that number is returned. If not, a 0 is returned.
This question was written by Jeremy Petersen.
It was last updated on January 12, 2006 at 1:54:46 PM EST.
CFML Referenced
Categories
Comments
Comment made by Ryan Guill on January 9, 2006 at 9:46 AM
Its worth noting that you can also use the isValid() function since cf 7+, of which using isValid("numeric",value) or isValid("float",value) is the functional equivalent of isNumeric(value), but isValid will also allow you to test for an integer, which isNumeric will not allow you to do.
Comment made by tanguy on January 13, 2006 at 8:00 AM
There's one "special" string that causes IsNumeric() to behave strangely: "NaN" (which stands for "not a number" and is returned by js when you try to use strings in math). CF claims that IsNumeric("NaN") = YES
Add a Comment