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?

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top