asp cint clng的范围与防止cint和clng的溢出解决方法大全


第一种:
一、检测它是不是整数

复制代码 代码如下:

function Is_Int(a_str)
if not isnumeric(a_str) or len(str) > 5 then
Is_Int = false
exit function
elseif len(str) < 5 then
Is_Int = true
exit function
end if
if cint(left(a_str , 4)) > 3276 then
Is_Int = false
exit function
elseif cint(left(a_str , 4)) = 3276 and cint(right(a_str , 1)) > 7 then
Is_Int = false
exit function
else
Is_Int = true
exit function
end if
end function




二、检测它是不是长整数

复制代码 代码如下:

function Is_Lng(a_str)
if not isnumeric(a_str) or len(str) > 10 then
Is_Lng = false
exit function
elseif len(str) < 10 then
Is_Lng = true
exit function
end if
if clng(left(a_str , 9)) > 214748367 then
Is_Lng = false
exit function
elseif clng(left(a_str , 9)) = 214748367 and clng(right(a_str , 1)) > 7 then
Is_Lng = false
exit function
else
Is_Lng = true
exit function
end if
end function

如果我们只需要是数子,其它的东西,都可以替换为空,下面这个是phpStudy站长写的一个正则,替换非数字的正则
复制代码 代码如下:

function replacestr(str)
dim re
set re=new regexp
re.ignorecase=true
re.global=true
re.pattern="\D"
str=re.replace(str,"")
replacestr=str
set re=nothing
end function

下面是上面的调用方法
复制代码 代码如下:

id=replacestr(id)
if len(id)>5 then id=left(id,5)
if id<>"" then id=clng(id)
if err.number<>0 Or id="0" then response.redirect "http://www.phpstudy.net"
dim rs
set rs=conn.execute("select id from news where id="&id&"")


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3