ASP isNumeric

You would assume that the isNumeric fucntion would return a false value if you passed it an alphanumeric string. However, after checking through some things; it appears that it considers 6,6 as an numeric value.

In this instance, the value is coming from a query string so you would assume that the variable sub-type would be a string. If you test that using the VarType function, it does indeed return a value of 8 (indicating VBString as the sub-type), yet some how it is also numeric.

The only way I can see that this is logical, is that it might be allowing the comma through based on the premise that it is a valid currency formatting character, such as $123,456.78. The Microsoft documentation for isNumeric indicates that it will allow a period (.) through, however mentions nothing about a comma at all.

A simple code example:

  1. Dim sValue
  2. sValue = 6
  3. Response.Write isNumeric(sValue) ' prints True
  4. sValue = 6.0
  5. Response.Write isNumeric(sValue) ' prints True
  6. sValue = "6,6"
  7. Response.Write isNumeric(sValue) ' prints True
  8. sValue = "6, 6"
  9. Response.Write isNumeric(sValue) ' prints False

If it is allowing the comma through for currency reasons then I would consider the function to be flawed. A comma isn’t part of a number system, it is part of a currency system which changes from country to country. Further to that point, if isNumeric considers “6,6″ to be a number, then you should also be allowed to cast it into a numeric type (from the variable sub-type VBString) into an integer for instance.

Related posts:

  1. PostgreSQL Dynamic SQL & Quote_ident Gotchas

About Al

My name is Alistair Lattimore, I'm in my very early 30's and live on the sunny Gold Coast in Australia. I married my high school sweet heart & we've been together for longer than I can remember. Claire and I started our family in September 2008 when Hugo was born and added a gorgeous little girl named Evie in May 2010. You can find me online in the typical hangouts, Google, Twitter & facebook. .
This entry was posted in Programming. Bookmark the permalink.

2 Responses to ASP isNumeric

  1. Caleb Rascon says:

    “A comma isn’t part of a number system, it is part of a currency system which changes from country to country.”

    You’re quite mistaken: in Mexico, and a lot of latin american countries, putting “1,234″ as a number is acceptable. And, the “6,6″ issue doesn’t just apply to currency, but to the whole numbering system in some countries: Great Britain, for instance, uses the comma as the decimal breakpoint: like “2.3 kilometers”, in England would be “2,3 kilometers”.

    Although I do agree that it’s flawed, but in the way that this function must be connected to the locale that’s setup in the server for it to know if the comma is acceptable in the “6,6″ manner, the “1,234″ manner or both.

  2. John says:

    A small correction, not entirely relevant, but the UK (and England) do not use the comma as a decimal place. Many places in Europe do, but not the UK (the English speaking countries in Europe)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>