在ASP中如何判断提交的表单是不是数字,急!!!

来源:百度知道 编辑:UC知道 时间:2024/05/18 04:43:10
我写了下面这一段代码,如何判断购买的数量(表单)不是数字:

<html>
<head><title>订票</title></head>
<body bgcolor="yellow" background="banner.jpg" topmargin="1">
<table border="0" cellspacing="0" style="border-collapse: collapse; border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 1; border-top-width: 1; border-bottom-width: 1; border-top-style:solid" bordercolor="#006D91" width="496" bgcolor="#EFEFEF" align="center" height="1">
<%=now%>  
<%
dim var_name
var_name=request.form("input_name")
dim var_num
var_num=request.form("input_num")
dim var_train_num
var_train_num=request.form("buy_num")
'response.write"" & var_num1 &""
dim Conn
Set Conn=Serve

判断数据是否为数字使用:

if not isnumeric(var_num) then
response.Write "不是数字格式"
end if

if not isnumeric(var_train_num) then
Response.Write "不是数字"
end if

发现你后边的SQL语句好像有问题
sql="insert into total_info(train_number,ticketnum,buyer)values('" & var_train_num & "','"& var_num &"','" & var_name & "')"

ticketnum字段是文本格式?
数字字段写入数据库两边不要有'
文本格式才是'"&aaa&"'
数字格式是: "&aaa&"

在客户端做判断,用正则表达式

dim var_num
var_num=request.form("input_num")
if not isnumeric( var_num ) then
response.write "不是数字"
end if