Search code examples
asp-classicisnumeric

Classic ASP IsNumeric weirdness?


Just ran into a rather strange bit of functionality with the baked in IsNumeric function is classic ASP.

I had a JSONArray class that prints out its contents to a string - it was using IsNumeric to determine whether or not to escape values with "'s. Everything was working fine until today a client reported a previously unseen error!

After some digging I found that a handful of records in the JSON array that was being returned from an AJAX call were poorly formed. More digging. Turns out strings that were formatted similar to '2D25' would be evaluated as numeric by IsNumeric and therefore not be escaped!

Does anyone know why this is? Does ASP think the D is interchangeable with a .?

Also, how should I go about fixing this? Would a regular expression be a better solution?

Thanks!


Solution

  • 2D25 is a hex value. See http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.information.isnumeric.aspx, in particular: "IsNumeric returns True if Expression is a string that contains a valid hexadecimal or octal number." RegEx is probably your best bet.

    <<< Edit :: Classic ASP Reference >>>

    http://classicasp.aspfaq.com/general/what-is-wrong-with-isnumeric.html

    In Classic ASP, the D is used to signal double precision.