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.

2 thoughts on “ASP isNumeric

  1. “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. 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)

Comments are closed.