网络编程
位置:首页>> 网络编程>> Asp编程>> ASP开发中有用的函数(function)集合(1)

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
投稿

猜你喜欢

  • FSO中除了可以对驱动器、文件夹的操作以外,功能最强大的就是对文件的操作了。它可以用来记数、内容管理、搜索还可生成动态HTML页面等等。一、
  •  <% Function ReplaceUrl2(HTMLstr) Dim n,st
  • 在你自己安装了一个新的MySQL服务器后,你需要为MySQL的root用户指定一个目录(缺省无口令),否则如果你忘记这点,你将你的MySQL
  • 在工作实践和学习中,如何开启 MySQL 数据库的远程登陆帐号算是一个难点的问题,以下内容便是在工作和实践中总结出来的两大步骤,能帮助DBA
  • 看到论坛上有人模仿alert,自己也写了一个。本来想模仿winapi里的MessageBox ;但可惜js 不支持,阻塞模式。返回值只能用异
  • “Be conservative in what you send; be liberal in what you accept. &nbs
  • 相信用过Gmail的人都知道Gmail有一个草稿自动保存的功能,每过一段时间,Gmail都会自动保存邮件草稿,这样在一些突 * 况下就能快速地
  • 最近一直在研究 Javascript 相关的技术。在《Javascript 高级程序设计》有篇章节着重阐述了优化 Javascri
  • dim sql_injdata,SQL_inj,SQL_Get,SQL_Data,Sql_PostSQL_injdata = "&
  • CREATE OR REPLACE PROCEDURE PROCSENDEMAIL(P_TXT       &
  • 本文实例介绍了如何使用ASP代码来读写注册表,呵呵厉害吧! 一个例子: <%Dim ReadComputerNam
  • 目的是想通过给定一个ID,取出所有的子ID,包括子ID的子ID。一开始写成FUNCTION,因为FUNCTION调用方便,但是报错:ERRO
  • 一、什么要备份数据库 ?在现实IT世界里,我们使用的服务器硬件可能因为使用时间过长,而发生故障;Windows系列服务器有可能蓝屏或者感染病
  • 设计是一个输入-输出的过程,因为首先有用户的需求,客户的项目才有设计的产生,设计是带有目的性和市场行为的,当然也有一部分的创造性设计,仅仅为
  • 1 引言 在关系数据库(DB2,Oracle,Sybase,Informix和SQL Server)最小的恢复和交易单位为一个事务(Tran
  • 我们平常用 IE 打开一个普通的本地 xml 文件,其形式通常都是如下图: 默认样式看得多了就不觉得有什么特别。但对于少接触 xml 的人来
  • 经常看到说正则的文章,但说的只是方法,却很少有说以下几个基本概念:1.贪婪:+,*,?,{m,n}等默认是贪婪匹配,即尽可能多匹配,也叫最大
  • Object 类型的对象虽然有 toString 方法,但结果却是 [Object Object] 让人没法理解的字符。比如简单的对象:{n
  • 当在设计中我们讨论到,对于一个功能或元素是否应该添加的时候,秉承“如无所需、勿增实体”的原则,我们通常会放弃只有小众/小部分人群才会使用的功
  • Create PROC P_viewPage        
手机版 网络编程 asp之家 www.aspxhome.com