Archive for the ‘validation’ Category

Making sure a number contains no letters with Coldfusion 8

Thursday, January 7th, 2010

This is just a heads up to those who are using the ‘isnumeric()’ function in Coldfusion to validate that a number is indeed a number.  What I noticed is that you can insert the letter ‘e’ into a number string and get back that the string is numeric.  The other few letters I tried did not pass the numeric test, but something like ‘1e20′ did pass.  I’m not sure exactly why this is, but I assume it may have something to do with character codes.  If anyone else may know why this is the case I would love to know.

The solution that I found is to use the ‘isvalid()’ method to check the given string that is supposed to be a number.  So taking our previous example, ‘isnumeric(“1e20″)’ will return true, but ‘isvalid(“integer”, “1e20″)’ will return false.