能代替int()函数的函数,同时功能更强,防止SQL注入

2 views
Skip to first unread message

翔龙

unread,
May 31, 2006, 4:23:48 AM5/31/06
to cntfly
<%
function
chk_num(page)'检测输入的是否是数字,如果不是返回0
on error resume next
dim numright
dim mynum
dim i
numright=1
dim fushu
fushu=0
if left(page,1)="-" then
fushu=1
end if
page=abs(page)
for i=1 to len(page)
mynum=mid(page,i,1)
if mynum<>"0" and mynum<>"1" and mynum<>"2" and mynum<>"3" and
mynum<>"4" and mynum<>"5" and mynum<>"6" and mynum<>"7" and mynum<>"8"
and mynum<>"9" and mynum<>"" then
numright=0
end if
next
if numright=1 and trim(page)<>"" then
if fushu=0 then
chk_num=clng(page)
else
chk_num=0-clng(page)
end if
else
chk_num=0
end if
end function
%>

Reply all
Reply to author
Forward
0 new messages