Search code examples
asp-classicisnumeric

IsNumeric() not working with Request.QueryString


I'm having problems trying to get IsNumeric to work properly with Request.QueryString.

The server is Windows 2008 R2 / IIS7.5

My code could not be any simpler:

    <%@ LANGUAGE=VBScript %>
    <% Response.Write "IsNumeric: " & IsNumeric(Request.QueryString("")) %>

My URL: http://localhost.com/default2.asp?44hjh

The output: IsNumeric: True

If I change my code to this, then I get the desired outcome:

    <%@ LANGUAGE=VBScript %>
    <% Response.Write "IsNumeric: " & IsNumeric(Request.QueryString("test")) %>

My URL: http://localhost.com/default2.asp?test=44hjh

The output: IsNumeric: False

Why does IsNumeric not work when I don't specify a specific querystring element? And more importantly, how can I fix it?


Solution

  • Request.QueryString("") doesn't exist and thus returns NULL -- there isn't a parameter that is a blank. IsNumeric of a NULL value will return True.

    Instead of using Request.QueryString(""), you can either supply the parameter as you did in your 2nd example, or just use Request.QueryString by itself assuming no other parameters are being passed to your page:

    <% Response.Write "IsNumeric: " & IsNumeric(Request.QueryString) %>