IsNumeric()函数判断输入的金额是否为数字型

  • 来源: 学赛网 作者: 若水   2008-04-23/16:19
  •    在进行商品信息添加时,为了确保录入信息的准确性与合法性,经常需要对添加的数据进行判断。例如,本实例主要应用IsNumeric()函数对用户输入的商品金额、商品数量进行判断,如果用户不小心输入了字符或其他非法的数据,系统将给予相应的提示信息,运行结果如图6.11所示。


    图6.11  应用IsNumeric()函数判断输入的商品金额是否为数字型

        通过以下代码判断用户输入的商品金额、商品数量是否合法。代码如下:
        <%
        set conn=server.CreateObject("adodb.connection")
        path=server.mappath("db_database.mdb")
        conn.open "Provider=Microsoft.jet.oledb.4.0;data source="&path
        if request.Form("name1")<>"" then
            name1=request.Form("name1")
                spje=request.Form("spje")
                if IsNumeric(spje) then
                             spje=request.Form("spje")
                     else
                             response.Write "<script lanage=javascript>alert('商品金额必须为数字类型');window.location.href='index.asp';</script>"
                     end if
            spsl=request.Form("spsl")
             if IsNumeric(spsl) then
               spsl=request.Form("spsl")
             else
                response.Write "<script lanage=javascript>alert('商品数量必须为数字类型');window.location.href='index.asp';</script>"
             end if
             username=request.Form("username")
             sccj=request.Form("sccj")
        sun="insert into tb_sp (name1,spje,spsl,username,sccj) values('"&name1&"','"&spje&"','"&spsl&"','"&username&"','"&sccj&"')"
        conn.execute(sun)
        end if
        %>


    评论 {{userinfo.comments}}

    {{money}}

    {{question.question}}

    A {{question.A}}
    B {{question.B}}
    C {{question.C}}
    D {{question.D}}
    提交

    驱动号 更多