This post will collect and solicit the most comprehensive general functional functions in ASP programming applications, everyone is for me, I am for everyone :)
As long as each of you gives out one or two classic general functions that you have collected for a long time, I think this post will be of great help to many ASP programming enthusiasts and workers, and will also become a necessary set of functions for everyone's ASP programming.
Check your own function library quickly and see if you have any of us here?
If you find that there are one or two little-known functions in your function library, then reply in the following format.
Publish a general function post format:
Copy the codeThe code is as follows:
<%
'******************************
'Function: Function RndIP(s)
'Parameter: s, four randomly generated IP headers, such as "218$211$61$221"
'Author: Alixi
'Date: 2007/7/12
'Description: Random IP address generation, return a random IP address value
'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
"The IP prefix parameter setting is incorrect. Please return to restart the program after resetting."
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 commonly used illegal characters
Copy the codeThe code is as follows:
<%
'******************************
'Function: ReplaceBadChar(strChar)
'Parameter: strChar, characters to be filtered
'Author: Ali Xixi
'Date: 2007/7/12
'Description: Filter commonly used illegal characters
'Example: <%=ReplaceBadChar("Example containing illegal characters")%>
'******************************
function ReplaceBadChar(strChar)
if strChar="" then
ReplaceBadChar=""
else
ReplaceBadChar=replace(replace(replace(replace(replace(replace(replace(strChar,"'",""),"*",""),"?",""),"(",""),")",""),"<",""),".","")
end if
end function
%>
Format HTML character display
Copy the codeThe code is as follows:
<%
'******************************
'Function: HTMLEncode(fString)
'Parameter: fString, string to be formatted
'Author: Ali Xixi
'Date: 2007/7/12
'Description: Format 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 non-repetitive random numbers, usually applied to file names generated by static HTML
Copy the codeThe code is as follows:
<%
'******************************
'Function: GetNewFileName
'Parameters: None
'Author: Ali Xixi
'Date: 2007/7/12
'Description: Generate non-repetitive random numbers, usually applied to file names generated by static HTML
'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 function
Copy the codeThe code is as follows:
<%
'******************************
'Function: IsValidEmail(email)
'Parameters: email, email address to be verified
'Author: Ali Xixi
'Date: 2007/7/12
'Description: Email Address Verification
'Example: <%=IsValidEmail(alixixi@)%>
'******************************
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
%>
12Next pageRead the full text