Question

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?

Was it helpful?

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) %>

OTHER TIPS

That's because isnumeric of a null value returns an integer type. That's why you get a TRUE in the first case. Whereas you are checking for a string type using the isnumeric in the second case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top