当前位置:编程学习 > asp >>

天枫常用的ASP函数封装如下

答案:

<%
'-------------------------------------
'天枫ASP class v1.0,集常用asp函数于一体
'天枫版权所有
'QQ:76994859 EMAIL:Chenshaobo@gmail.com
'所有功能函数名如下:
' StrLength(str) 取得字符串长度
' CutStr(str,strlen) 字符串长度切割
' CheckIsEmpty(tstr) 检测是否为空
' isInteger(para) 整数检验
' CheckName(str) 名字字符校验
' CheckPassword(str) 密码检验
' CheckEmail(email) 邮箱格式检验
' Alert(msg,goUrl) 弹出对话框提示
' GoBack(Str1,Str2,isback) 出错信息提示
' Suc(str1,str2,url) 操作成功信息提示
' ChkPost() 检测是否站外提交表单
' PSql() 防止sql注入
' FiltrateHtmlCode(Str) 防止生成HTML
' HtmlCode(str) 过滤HTML
' Replacehtml(tstr) 清滤HTML
' GetIP() 获取客户端IP
' GetBrowser 获取客户端浏览器信
' GetSystem 获取客户端操作系统
' GetUrl() 获取当前页面URL包含参数
' CUrl() 获取当前页面URL
' GetExtend 取得文件扩展名
' CheckExist(table,fieldname,fieldcontent,isblur) 检测某个表中某个字段的内容是否存在
' GetNum(table,fieldname,resulttype,args) 检测某个表某个字段有多少条,最大值 ,最小值等
' GetFolderSize(Folderpath) 计算某个文件夹的大小
' GetFileSize(Filename) 计算某个文件的大小
' IsObjInstalled(strClassString) 检测组件是否安装
' SendMail JMAIL发送邮件
' ResponseCookies 写入cookies
' CleanCookies 清除cookies
' GetTimeover 取得程序页面执行时间
' FormatSize 大小格式化
' FormatTime 时间格式化
' Zodiac 取得生肖
' Constellation 取得星座
'-------------------------------------
Class Cls_fun
'--------字符处理--------------------------
'****************************************************
'函数名:StrLength
'作 用:取得字符串长度(汉字为2)
'参 数:str ----字符串内容
'返回值:字符串长度
'****************************************************
Public function StrLength(str)
Dim Rep,lens,i
Set rep=new regexp
rep.Global=true
rep.IgnoreCase=true
rep.Pattern="[\u4E00-\u9FA5\uF900-\uFA2D]"
For each i in rep.Execute(str)
lens=lens+1
Next
Set Rep=Nothing
lens=lens + len(str)
strLength=lens
End Function
'****************************************************
'函数名:CutStr
'作 用:字符串长度切割,超过显示省略号
'参 数:str ----字符串内容
' strlen ------要显示的长度
'返回值:切割后字符串内容
'****************************************************
Public Function CutStr(str,strlen)
Dim l,t,i,c
If str="" Then
cutstr=""
Exit Function
End If
str=Replace(Replace(Replace(Replace(Replace(str," "," "),""",Chr(34)),">",">"),"<","<"),"|","|")
l=Len(str)
t=0
For i=1 To l
c=Abs(Asc(Mid(str,i,1)))
If c>255 Then
t=t+2
Else
t=t+1
End If
If t>=strlen Then
cutstr=Left(str,i) & "..."
Exit For
Else
cutstr=str
End If
Next
cutstr=Replace(Replace(Replace(Replace(replace(cutstr," "," "),Chr(34),"""),">",">"),"<","<"),"|","|")
End Function
'--------------系列验证----------------------------
'****************************************************
'函数名:CheckIsEmpty
'作 用:检查是否为空
'参 数:tstr ----字符串
'返回值:true不为空,false为空
'****************************************************
Public Function CheckIsEmpty(tstr)
CheckIsEmpty=false
If IsNull(tstr) or Tstr="" Then Exit Function
Dim Str,re
Str=Tstr
Set re=new RegExp
re.IgnoreCase =True
re.Global=True
str= Replace(str, vbNewLine, "")
str = Replace(str, Chr(9), "")
str = Replace(str, " ", "")
str = Replace(str, " ", "")
re.Pattern="<img(.[^>]*)>"
str =re.Replace(Str,"94kk")
re.Pattern="<(.[^>]*)>"
Str=re.Replace(Str,"")
Set Re=Nothing
If Str<>"" Then CheckIsEmpty=true
End Function
'****************************************************
'函数名:isInteger
'作 用:整数检验
'参 数:tstr ----字符
'返回值:true是整数,false不是整数
'****************************************************
Public function isInteger(para)
on error resume Next
Dim str
Dim l,i
If isNUll(para) then
isInteger=false
exit function
End if
str=cstr(para)
If trim(str)="" then
isInteger=false
exit function
End if
l=len(str)
For i=1 to l
If mid(str,i,1)>"9" or mid(str,i,1)<"0" then
isInteger=false
exit function
End if
Next
isInteger=true
If err.number<>0 then err.clear
End Function
'****************************************************
'函数名:CheckName
'作 用:名字字符检验
'参 数:str ----字符串
'返回值:true无误,false有误
'****************************************************
Public Function CheckName(Str)
Checkname=true
Dim Rep,pass
Set Rep=New RegExp
Rep.Global=True
Rep.IgnoreCase=True
'匹配字母、数字、下划线、汉字且必须以字母或下划线或汉字开始
Rep.Pattern="^[a-zA-Z_u4e00-\u9fa5][\w\u4e00-\u9fa5]+$"
Set pass=Rep.Execute(Str)
If pass.count=0 Then CheckName=false
Set Rep=Nothing
End Function
'****************************************************
'函数名:CheckPassword
'作 用:密码检验
'参 数:str ----字符串
'返回值:true无误,false有误
'****************************************************
Public Function CheckPassword(Str)
Dim pass
CheckPassword=true
If Str <> "" Then
Dim Rep
Set Rep = New RegExp
Rep.Global = True
Rep.IgnoreCase = True
'匹配字母、数字、下划线、点号
Rep.Pattern="[a-zA-Z0-9_\.]+$"
Pass=rep.Test(Str)
Set Rep=nothing
If not Pass Then CheckPassword=false
End If
End Function
'****************************************************
'函数名:CheckEmail
'作 用:邮箱格式检测
'参 数:str ----Email地址
'返回值:true无误,false有误
'****************************************************
Public function CheckEmail(email)
CheckEmail=true
Dim Rep
Set Rep = new RegExp
rep.pattern="([\.a-zA-Z0-9_-]){2,10}@([a-zA-Z0-9_-]){2,10}(\.([a-zA-Z0-9]){2,}){1,4}$"
pass=rep.Test(email)
Set Rep=Nothing
If not pass Then CheckEmail=false
End function
'--------------信息提示----------------------------
'****************************************************
'函数名:Alert
'作 用:弹出对话框提示
'参 数:msg ----对话框信息
' gourl ----提示后转向哪里
'返回值:无
'****************************************************
Public Function Alert(msg,goUrl)
msg = replace(msg,"'","\'")
If goUrl="" Then
goUrl="history.go(-1);"
Else
goUrl="window.location.href=> End IF
Response.Write ("<script language=""JavaScript"" type=""text/javascript"">"&vbNewLine&"alert('" & msg & "');"&goUrl&vbNewLine&"</script>")
Response.End
End Function
'****************************************************
'函数名:GoBack
'作 用:错误信息提示
'参 数:str1 ----信息提示标题
' str2 ----信息提示内容 <

上一个:ASP把长的数字用逗号隔开显示的代码
下一个:ASP+模板生成Word、Excel、html的代码第1/2页

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,