搜索|收藏|地图|订阅|图片|论坛|商城

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

来源:学赛网 编辑:若水 时间:2008-04-23
   在进行商品信息添加时,为了确保录入信息的准确性与合法性,经常需要对添加的数据进行判断。例如,本实例主要应用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
    %>

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?