文跃's profile难得糊涂PhotosBlogLists Tools Help

Blog


    November 27

    asp 一些常用的函数

    <%
    '判断EMAIL是否正确
    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 IsValidTel(para)
     Dim Str
     Dim l, i
     If IsNull(para) Then
      IsValidTel = false
      Exit Function
     End If
     Str = CStr(para)
     If Len(Trim(Str))<7 Then
      IsValidTel = false
      Exit Function
     End If
     l = Len(Str)
     For i = 1 To l
      If Not (Mid(Str, i, 1)>= "0" And Mid(Str, i, 1)<= "9" Or Mid(Str, i, 1) = "-") Then
       IsValidTel = false
       Exit Function
      End If
     Next
     IsValidTel = true
    End Function
    Rem 判断数字是否整形
    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
    '检测文件类型
    Function CheckFileExt(FileExt)
     Dim ForumUpload,i
     ForumUpload="gif,jpg,bmp,jpeg,png,swf,pdf,rar,zip,Doc"
     ForumUpload=Split(ForumUpload,",")
     CheckFileExt=False
     For i=0 to UBound(ForumUpload)
      If LCase(FileExt)=Lcase(Trim(ForumUpload(i))) Then
       CheckFileExt=True
       Exit Function
      End If
     Next
    End Function
    Rem 过滤HTML代码
    function HTMLEncode(fString)
    if not isnull(fString) then
        fString = replace(fString, ">", "&gt;")
        fString = replace(fString, "<", "&lt;")
        fString = Replace(fString, CHR(32), "&nbsp;")
        fString = Replace(fString, CHR(9), "&nbsp;")
        fString = Replace(fString, CHR(34), "&quot;")
        fString = Replace(fString, CHR(39), "&#39;")
        fString = Replace(fString, CHR(13), "")
        fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
        fString = Replace(fString, CHR(10), "<BR>")
        HTMLEncode = fString
    else
       HTMLEncode=fstring
    end if
    end function
    '报错函数
    sub errorInfo(str_error)
    Response.write"<script>alert('"&str_error&"');location.href=""javascript:history.back(-1);"";</script>"
    Response.end
    end sub
    sub selfClose(str_error)
    Response.write"<script>alert('" &str_error & "');window.close();</script>"
    Response.end
    end sub
    '同行多列显示 标题
    'rstitle 记录集rs
    'cols 分几列
    'title 标题名
    'id 传参id
    'url 链接地址
    Function col(rstitle,cols,title,id,url)
     dim j,b_title,b_id,colb
     colb=100/cols
     response.Write "<tr>" & vbCrLf
     if (rstitle.eof and rstitle.bof) then
      response.Write "<td>&nbsp;暂时没有相关信息</td>" & vbCrLf
     else
      j=1
      do while not rstitle.eof
      b_title=rstitle(title)
      b_id=rstitle(id)
      response.Write "" & vbCrLf
      if j mod cols=0 then
       response.Write "</tr><tr>" & vbCrLf
      end if
      j=j+1
      rstitle.movenext
      loop
       response.Write "</tr>" & vbCrLf
     end if
    End Function
    %>

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Nov. 27

    Trackbacks

    The trackback URL for this entry is:
    http://wenyueb.spaces.live.com/blog/cns!ED01E7270578387F!203.trak
    Weblogs that reference this entry
    • None