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

资讯 驱动中国 若水 2,474 次阅读 0 条评论
分享 Q

   在进行商品信息添加时,为了确保录入信息的准确性与合法性,经常需要对添加的数据进行判断。例如,本实例主要应用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
    %>

版权声明:本文由驱动中国整理发布,转载需注明出处与原文链接。如有疑问请联系 editor@qudong.com
本文价值 成为第一个评分的人
登录后为本文打分
网友评论0 条评论
正在回复 的评论取消
评论加载中…
🔐

登录后参与互动

评论、点赞均可赚积分
连续签到、邀请好友也有奖励 🎁

电脑端: 微信扫码登录 微信内: 一键登录

微信扫一扫

打开微信「扫一扫」,分享本文到朋友圈或好友