ASP开发中有用的函数(function)集合(1)

作者:站长整理 来源:网页教学网 时间:2008-10-14 17:10:00 



ASP开发中有用的function集合,挺有用处的!希望大家保留!

<%    
'*************************************   
'防止外部提交   
'*************************************   
function ChkPost()    
  dim server_v1,server_v2   
  chkpost=false   
  server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))   
  server_v2=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   
  
'*************************************   
'IP过滤   
'*************************************    
function MatchIP(IP)   
 on error resume next   
 MatchIP=false   
 Dim SIp,SplitIP   
 for each SIp in FilterIP   
    SIp=replace(SIp,"*","\d*")   
    SplitIP=split(SIp,".")   
    Dim re, strMatchs,strIP   
     Set re=new RegExp   
      re.IgnoreCase =True  
      re.Global=True  
      re.Pattern="("&SplitIP(0)"|).""("&SplitIP(1)"|).""("&SplitIP(2)"|).""("&SplitIP(3)"|)"  
     Set strMatchs=re.Execute(IP)   
      strIP=strMatchs(0).SubMatches(0) & "." & strMatchs(0).SubMatches(1)& "." & strMatchs(0).SubMatches(2)& "." & strMatchs(0).SubMatches(3)   
     if strIP=IP then MatchIP=true:exit function   
     Set strMatchs=Nothing  
     Set re=Nothing  
 next    
end function   
    
'*************************************   
'获得注册码   
'*************************************     
Function getcode()    
    getcode= "<img src=""common/getcode.asp"" alt="""" style=""margin-right:40px;""/>"         
End Function  
  
'*************************************   
'限制上传文件类型   
'*************************************     
Function IsvalidFile(File_Type)   
    IsvalidFile = False  
    Dim GName   
    For Each GName in UP_FileType   
        If File_Type = GName Then  
            IsvalidFile = True  
            Exit For  
        End If  
    Next  
End Function  
  
'*************************************   
'检测是否只包含英文和数字   
'*************************************    
Function IsValidChars(str)   
    Dim re,chkstr   
    Set re=new RegExp   
    re.IgnoreCase =true   
    re.Global=True  
    re.Pattern="[^_\.a-zA-Z\d]"  
    IsValidChars=True  
    chkstr=re.Replace(str,"")   
    if chkstr<>str then IsValidChars=False  
    set re=nothing   
End Function  
  
'*************************************   
'检测是否只包含英文和数字   
'*************************************    
Function IsvalidValue(ArrayN,Str)   
    IsvalidValue = false   
    Dim GName   
    For Each GName in ArrayN   
        If Str = GName Then  
             IsvalidValue = true   
            Exit For  
        End If  
    Next  
End Function    
  
'*************************************   
'检测是否有效的数字   
'*************************************   
Function IsInteger(Para)    
    IsInteger=False  
    If Not (IsNull(Para) Or Trim(Para)="" Or Not IsNumeric(Para)) Then  
        IsInteger=True  
    End If  
End Function  
  
'*************************************   
'用户名检测   
'*************************************   
Function IsValidUserName(byVal UserName)   
    on error resume next   
    Dim i,c   
    Dim VUserName   
    IsValidUserName = True  
    For i = 1 To Len(UserName)   
        c = Lcase(Mid(UserName, i, 1))   
        If InStr("$!<>?#^%@~`&*();:+='""   ", c) > 0 Then  
                IsValidUserName = False  
                Exit Function  
        End IF   
    Next  
    For Each VUserName in Register_UserName   
        If UserName = VUserName Then  
            IsValidUserName = False  
            Exit For  
        End If  
    Next  
End Function  
  
'*************************************   
'检测是否有效的E-mail地址   
'*************************************   
Function IsValidEmail(Email)    
    Dim names, name, i, c   
    IsValidEmail = True  
    Names = Split(email, "@")   
    If UBound(names) <> 1 Then  
        IsValidEmail = False  
        Exit Function  
    End If  
    For Each name IN names   
        If Len(name) <= 0 Then  
            IsValidEmail = False  
            Exit Function  
        End If  
        For i = 1 to Len(name)   
            c = Lcase(Mid(name, i, 1))   
            If InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 And Not IsNumeric(c) Then  
                IsValidEmail = false   
                Exit Function  
            End If  
        Next  
        If Left(name, 1) = "." or Right(name, 1) = "." Then  
            IsValidEmail = false   
            Exit Function  
        End If  
    Next  
    If InStr(names(1), ".") <= 0 Then  
        IsValidEmail = False  
        Exit Function  
    End If  
    i = Len(names(1)) - InStrRev(names(1), ".")   
    If i <> 2 And i <> 3 Then  
        IsValidEmail = False  
        Exit Function  
    End If  
    If InStr(email, "..") > 0 Then  
        IsValidEmail = False  
    End If  
End Function  
  
'*************************************   
'加亮关键字   
'*************************************   
Function highlight(byVal strContent,byRef arrayWords)   
    Dim intCounter,strTemp,intPos,intTagLength,intKeyWordLength,bUpdate   
    if len(arrayWords)<1 then highlight=strContent:exit function   
    For intPos = 1 to Len(strContent)   
        bUpdate = False  
        If Mid(strContent, intPos, 1) = "<" Then  
            On Error Resume Next  
            intTagLength = (InStr(intPos, strContent, ">", 1) - intPos)   
            if err then   
              highlight=strContent   
              err.clear   
            end if   
            strTemp = strTemp & Mid(strContent, intPos, intTagLength)   
            intPos = intPos + intTagLength   
        End If  
            If arrayWords <> "" Then  
                intKeyWordLength = Len(arrayWords)   
                If LCase(Mid(strContent, intPos, intKeyWordLength)) = LCase(arrayWords) Then  
                    strTemp = strTemp & "<span class=""high1"">" & Mid(strContent, intPos, intKeyWordLength) & "</span>"  
                    intPos = intPos + intKeyWordLength - 1   
                    bUpdate = True  
                End If  
            End If  
        If bUpdate = False Then  
            strTemp = strTemp & Mid(strContent, intPos, 1)   
        End If  
    Next  
    highlight = strTemp   
End Function

标签:
0
投稿

猜你喜欢

  • 淘宝CSS框架研究(1):Reset CSS(八卦篇)

    2009-03-31 12:58:00
  • OBJECTPROPERTY与sp_rename更改对象名称的介绍

    2012-01-29 18:04:39
  • JS中模拟函数重载

    2008-01-03 16:46:00
  • Oracle 启动例程 STARTUP参数说明

    2009-07-07 10:26:00
  • JavaScript组件打包模式

    2010-04-08 16:26:00
  • 通过session在ASP中改善动态分页的性能

    2007-09-11 14:00:00
  • 使用Javascript动态增加,删除表格

    2008-02-03 19:15:00
  • asp如何创建一个PDF文件?

    2009-11-14 20:53:00
  • 类型转换的小乐趣

    2010-11-30 21:37:00
  • 怎样管理好css样式

    2008-10-12 12:12:00
  • 设计模式-自动完成

    2010-11-30 21:44:00
  • 正则表达式学习笔记

    2008-04-15 07:44:00
  • 卸载VS2011 Developer Preview后Sql Server2008 R2建立数据库关系图报“找不到指定的模块”错误的解决方法

    2011-11-03 16:49:09
  • 如何使用Index Server建立一个网站导航地图?

    2010-06-05 12:39:00
  • 无刷新dropdownlist并进行关联(js+xml)

    2007-09-23 12:13:00
  • 如何使用SQLServer数据库查询累计值

    2009-03-16 14:43:00
  • 实现框架页面iframe的背景透明方法

    2008-06-18 12:21:00
  • asp采集常用的几个FUCTION

    2007-09-05 19:45:00
  • 两组字符串数据比较合并相同数据

    2008-07-31 17:27:00
  • 十万条Access数据表分页的两个解决方法

    2008-05-23 18:24:00
  • asp之家 网络编程 m.aspxhome.com