简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM