This post will collect and collect the most comprehensive functions used in ASP programming applications. Everyone is me and everyone is me :)
As long as each person provides one or two collections of well-known general functions, I think this post will be of great help to many ASP programmers and workers, it will also become a necessary function set for ASP programming.
Check your own function library and check if you have all of them here?
If you find that there are one or two less-known functions in your function library, please reply in the following format.
Format of posting a general function post:
Copy codeThe Code is as follows: <%
'******************************
'Function: Function RndIP (s)
'Parameter: s, four randomly generated IP headers, such as "218 $211 $61 $221"
'Prepared by: alixixi
'Date: 2007/7/12
Description: random IP address generation. A random IP address value is returned.
'Example: <% = RndIP ("218 $211 $61 $221") %>
'******************************
Function RndIP (s)
On error resume next
Dim ip, ip1, ip2, ip3, a, B, c
If s = "" or ubound (split (s, "$") <> 3 then
Response. write "IP prefix parameter setting error. Please return and reset and start the program. "
Response. end
End if
Randomize
Ip1 = cInt (254 * rnd)
Ip2 = cInt (254 * rnd)
Ip3 = cInt (254 * rnd)
B = Int (3 * rnd) + 1)
A = Split (s, "$ ")
C = a (B)
RndIP = (c & "." & ip1 & "." & ip2 & "." & ip3)
End Function
%>
Filter common invalid charactersCopy codeThe Code is as follows: <%
'******************************
'Function: ReplaceBadChar (strChar)
'Parameter: strChar, to be filtered
'Prepared by: alixixi
'Date: 2007/7/12
'Description: used to filter out invalid characters.
'Example: <% = ReplaceBadChar ("' * example" containing invalid characters) %>
'******************************
Function ReplaceBadChar (strChar)
If strChar = "" then
ReplaceBadChar = ""
Else
ReplaceBadChar = replace (strChar ,"'",""),"*",""),"? "," ")," ("," "),") "," ")," <",""),".","")
End if
End function
%>
Format HTML character displayCopy codeThe Code is as follows: <%
'******************************
'Function: HTMLEncode (fString)
'Parameter: fString, string to be formatted
'Prepared by: alixixi
'Date: 2007/7/12
'Description: format the HTML character display.
'Example: <% = HTMLEncode (fString) %>
'******************************
Function HTMLEncode (fString)
If not isnull (fString) then
FString = replace (fString, ">", "> ")
FString = replace (fString, "<", "<")
FString = Replace (fString, CHR (32 ),"")
FString = Replace (fString, CHR (9 ),"")
FString = Replace (fString, CHR (34 ),""")
FString = Replace (fString, CHR (39 ),"'")
FString = Replace (fString, CHR (13 ),"")
FString = Replace (fString, CHR (10) & CHR (10 ),"")
FString = Replace (fString, CHR (10 ),"")
HTMLEncode = fString
End if
End function
%>
Generate random numbers that are not repeated, usually used for static HTML file namesCopy codeThe Code is as follows: <%
'******************************
'Function: GetNewFileName
'Parameter: None
'Prepared by: alixixi
'Date: 2007/7/12
'Description: generate random numbers that are not repeated. They are usually used for static HTML file names.
'Example: <% = GetNewFileName () %>
'******************************
Function GetNewFileName ()
Dim ranNum
Dim dtNow
DtNow = Now ()
RanNum = int (90000 * rnd) + 10000
GetNewFileName = year (dtNow) & right ("0" & month (dtNow), 2) & right ("0" & day (dtNow), 2) & right ("0" & hour (dtNow), 2) & right ("0" & minute (dtNow), 2) & right ("0" & second (dtNow ), 2) & ranNum
End Function
%>
Email address verification functionCopy codeThe Code is as follows: <%
'******************************
'Function: IsValidEmail (email)
'Parameter: email, the email address to be verified
'Prepared by: alixixi
'Date: 2007/7/12
Description: email address verification.
'Example: <% = IsValidEmail (alixixi@msn.com) %>
'******************************
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)-faster Rev (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
%>