栏目导航
热点推荐
- ASP下批量删除数据的两种方法
- 关于二级域名共享cookies
- ASP错误代码大全
- ASP代码实现show.asp?id=26变成s
- ASP错误信息解决:IIS启用父路径
- 一些常用的正则表达式大全
- ASP超级链接和HTML函数正则表达
- ASP隐藏下载地址及防盗代码
- 最常用的正则表达式示例
- ASP程序数据库被挂马的处理方法
- ASP生成html的新方法
- 精通ASP错误提示大全
阅览排行
ASP常用代码段之二
www.jz123.cn 2010-09-29 来源: 中国建站 责任编辑(袁袁) 我要投递新闻
1:asp判断发言是否来自外部
'ChkPost=false 来自外部提交(非法)
'ChkPost=true 合法提交表单
function ChkPost() dim server_v1,server_v2 chkpost=false server_v1=LCase(Cstr(Request.ServerVariables("HTTP_REFERER"))) server_v2=LCase(Cstr(Request.ServerVariables("SERVER_NAME"))) if mid(server_v1,8,len(server_v2))<>server_v2 then chkpost=false else chkpost=true end if end function |
2:asp实现向数据库中任何表中添加、删除、修改内容
<% '=========================================== ' 函数功能:实现向数据库中任何表中添加、删除、修改内容 ' 作 者:wangsdong ' 网 站: http://www.aspprogram.cn ' 文章为作者原创,转载请注明文章出处、保留作者信息,谢谢支持! ' 参数意义:tablename为表名,str的值是insert,delete,update 表示 ' 要执行的语句是添加、删除、修改。id为自动编号类型字段,使用方 ' 法见举例 '=========================================== Function add_del_update(tablename,str,id) Select Case str Case "insert": sql="select * from ["&tablename&"] where id=null" rs.open sql,conn,1,3 rs.addnew For Each key In request.Form rs(CStr(key))=request(key) Next rs.update rs.close Case "update": sql="select * from ["&tablename&"] where id="&id rs.open sql,conn,1,3 For Each key In request.Form if key<>"id" then rs(CStr(key))=request(key) end if Next rs.update rs.close Case "delete": sql="delete from ["&tablename&"] where id in("&id&")" rs.open sql,conn,1,3 Case "" End Select End Function %> |
3:ASP身份证号码验证函数
//var sss = "422324860305482"; //Response.Write(checkIDCard(sss, "03/05/1986", 0)); function checkIDCard(s, d, g) { if (!s) return false; d = new Date(d); if (!d.getTime()) return false; var t, r; t = "" + d.getFullYear() + dblNum(d.getMonth() + 1) + dblNum(d.getDate()); if (g == null || isNaN(g)) return false; g = parseInt(g) % 2; switch (s.length) { case 8 : if (new Date() > d.setFullYear(d.getFullYear() + 19)) return false; r = /^[\d]{8}$/; if (!r.test(s)) return false; if (s != t) return false; break; case 15 : r = /^[\d]{15}$/; if (!r.test(s)) return false; if (s.substr(6, 6) != t.substr(2)) return false; if (parseInt(s.charAt(14)) % 2 != g) return false; break; case 18 : r = /^(?:[\d]{18}|[\d]{17}X)$/i; if (!r.test(s)) return false; if (s.substr(6, 8) != t) return false; if (parseInt(s.charAt(16)) % 2 != g) return false; var n = 0; var w = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); // 加权因子 var c = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"); // 校验码 for (var i = 0; i < 17; i++) { n += parseInt(s.charAt(i)) * w[i]; } if (s.charAt(17).toUpperCase() != c[n % 11]) return false; break; default : return false; } return true; } function dblNum(n) { return parseInt(n) < 10 ? "0" + n : n; } |
4:asp格式化日期时间(显示)
' ============================================ ' 格式化日期时间(显示) ' 参数:n_Flag ' 1:"yyyy-mm-dd hh:mm:ss" ' 2:"yyyy-mm-dd" ' 3:"hh:mm:ss" ' 4:"yyyy年mm月dd日" ' 5:"yyyymmdd" ' 6:"yyyymmddhhmmss" ' 7:"yy-mm-dd" ' 8:"yy-mm-dd hh:mm:ss" ' 9:"yyyy年mm月" ' 10:"mm/dd/yyyy" ' ============================================ Function Format_Time(s_Time, n_Flag) Dim y, m, d, h, mi, s Format_Time = "" If IsDate(s_Time) = False Then Exit Function y = cstr(year(s_Time)) if y = "1900" then Exit Function m = right("0"&month(s_Time),2) d = right("0"&day(s_Time),2) h = right("0"&hour(s_Time),2) mi = right("0"&minute(s_Time),2) s = right("0"&second(s_Time),2) Select Case n_Flag Case 1 Format_Time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s Case 2 Format_Time = y & "-" & m & "-" & d Case 3 Format_Time = h & ":" & mi & ":" & s Case 4 Format_Time = y & "年" & m & "月" & d & "日" Case 5 Format_Time = y & m & d case 6 Format_Time= y & m & d & h & mi & s case 7 Format_Time= right(y,2) & "-" & m & "-" & d case 8 Format_Time= right(y,2) & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s Case 9 Format_Time = y & "年" & m & "月" Case 10 Format_Time = m & "/" & d & "/" & y & "/" End Select End Function |
5:asp小写数字转大写
function int2chn(n) dim i,j,k,strlen,retval,x,y,z,str z=array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖") y=array("","拾","佰","仟") x=Array("","万","亿","万万亿") strlen=len(n) str1=n for i= 1 to strlen j=mid(str1,i,1) retval=retval&z(j) if j>0 then retval=retval&y((strlen-i) mod 4)'如果大于零,加入十进位字符 retval=replace(retval,z(0)&z(0),z(0))'出现两个零只留一个 if ((strlen-i) mod 4)=0 and right(retval,1)=z(0) then retval=left(retval,len(retval)-1)'每四位加入进阶 if ((strlen-i) mod 4)=0 then retval=retval&x(int((strlen-i)/4))'把最后的零去掉 next int2chn=retval end function |
6:asp小写金额转大写
Function UMoney(money) Dim lnP,Prc,Tmp,NoB,Dx,Xx,Zhen Dim China : China = "分角元拾佰仟万拾佰仟亿" Dim str: str = Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖") Zhen = True money = FormatNumber(money, 2) Prc = CStr(money) Prc = Replace(Prc, ",", "") lnP = Len(Prc) For i = lnP - 1 To 1 Step -1 If Mid(Prc, i, 1) = "." Then Select Case lnP - i Case 1 Prc = Replace(Prc, ".", "") + "0" Case 2 Prc = Replace(Prc, ".", "") End Select Zhen = False Exit For End If Next If Zhen Then Prc = Prc + "00" lnP = Len(Prc) For i = 1 To lnP Tmp = str(Mid(Prc, i, 1)) & Tmp Next UMoney = "" fy = 1 For i = 1 To lnP Xx = Mid(Tmp, i, 1) Dx = Mid(China, i, 1) If Xx <> "零" Then UMoney = Xx & Dx & UMoney f = 1 Else If i = 3 Then UMoney = Dx & UMoney End If If i = 7 Then UMoney = Dx & UMoney End If If f Then UMoney = "零" & UMoney End If f = 0 End If Next If Zhen Then UMoney = UMoney + "整" UMoney = Replace(UMoney, "零万", "万") UMoney = Replace(UMoney, "零元", "元") End Function |
7:asp随机选取5组彩票
Function rndtest(m_count,r_count) ''参数m_count号码总数,r_count为要取出的号码数 dim x,st,i i=1 st="" do while i<=r_count randomize x=int(rnd*m_count)+1 ''产生1~m_count的随机数 if i=r_count then if not instr(st,x)>0 then st=st&x i=i+1 end if else if not instr(st,x)>0 then st=st&x&"," ''用,分割 i=i+1 end if end if if i>=m_count then exit do ''如果m_count小于r_count将出现死循环,于是判断并跳出循环 end if loop rndtest=st end function function sort(ary)'冒泡函数 ck=true do Until ck = false ck=false For f = 0 to UBound(ary) -1 if clng(ary(f))>clng(ary(f+1)) then v1=clng(ary(f)) v2=clng(ary(f+1)) ary(f)=v2 ary(f+1)=v1 ck=true end if next loop sort=ary end function for i=0 to 4 Mycount=rndtest(33,7) MyArray=split(Mycount,",") newArray=sort(MyArray) for i2=0 to UBound(newArray) Response.Write(newArray(i2)&" ") next Response.Write("<br>") next |
8:asp对非法字符进行过滤
'此文件可以对整站提交文字进行过滤
'编写者:逸风
'编写日期:2008-6-4
'函数说明:对非法字符进行过滤
'这个函数将过滤所有非中文字符
function ClearString(str)
dim re,str1,str2,i
set re = new regexp re.Pattern = "^[\u4e00-\u9fa5\s\n\r\t]+$"
for i=1 to len(str)
str1 = mid(str,i,1)
clearString = re.Test(str1)
if clearString=true then
str2 = str2&str1
end if
next
str=str2
ClearString = str
end function
function KillKey(str)
KillKey=str
end function
'编写者:逸风
'编写日期:2008-6-4
'函数说明:对非法字符进行过滤
'这个函数将过滤所有非中文字符
function SearchKey(str)
Key="这里是非法字符 嘎嘎`~~CSDN也屏蔽的"
KeyArray=split(Key,",")
K=ubound(KeyArray)
str2=ClearString(str)
for i=0 to K
if Instr(str2,KeyArray(i)) then
response.Write("<font color=red>您所提交的信息中包含非法字符,请您返回后仔细检查所填写的内容然后再次提交您的信息!</font><a href='javascript:history.go(-1);'>返回</a><br/><font color=#0000FF>感谢您的支持!</font><br/>非法字符:" & KeyArray(i))
response.End()
end if
next
SearchKey=str
end function
function urldecode(encodestr) 'encodestr就是要解码的字符串
Dim newstr,havechar,lastchar,i,char_c,next_1_c,next_1_Num
newstr=""
havechar=false
lastchar=""
for i=1 to len(encodestr)
char_c=mid(encodestr,i,1)
if char_c="+" then
newstr=newstr & " "
elseif char_c="%" then
next_1_c=mid(encodestr,i+1,2)
next_1_num=cint("&H" & next_1_c)
if havechar then
havechar=false
newstr=newstr & chr(cint("&H" & lastchar & next_1_c))
else
if abs(next_1_num)<=127 then
newstr=newstr & chr(next_1_num)
else
havechar=true
lastchar=next_1_c
end if
end if
i=i+2
else
newstr=newstr & char_c
end if
next
urldecode=newstr
end function
TempStr1=urldecode(request.QueryString)
TempStr2=urldecode(request.Form)
'查询提交的信息 如有非法字符 直接终止程序运行
SearchKey(TempStr1)
SearchKey(TempStr2)
上一篇:ASP常用代码段之一 下一篇:ASP常用代码段之三