Xử lý dấu nháy đơn khi request form với ASP

<%

For each FormElement in Request.Form
s = Request.Form(FormElement)
re = Replace(s, ” ‘ “, ” ‘ ‘ “)
Next

%>

Hàm dùng để phân trang:

function do_pagination(current_page, total_pages)

current_page = cint(current_page)
dim url
dim strPages : strPages = “”
dim intMaxPages
dim intMinPages
dim intPaginI

‘ We start be building the URL to add the current_page
‘variable to … by removing the old current_page data

dim objRegExp : set objRegExp = new RegExp
objRegExp.Pattern = “(&|?)?current_page=[^&]*(&|$)”
objRegExp.IgnoreCase = true
objRegExp.Global = true
url = objRegExp.replace(request.ServerVariables(“SCRIPT_NAME”) & “?” & request.ServerVariables(“QUERY_STRING”), “$1”)
set objRegExp = nothing

if (right(url, 1) = “&”) then
url = left(url, len(url)-1)
end if

if (right(url, 1) = “?”) then
url = left(url, len(url)-1)
end if

‘ Right, now we’ve got a clean url. Add a character
‘to precede the new current_page value, and off we go!

if (instr(url, “?”) > 0) then
url = url & “&”
else
url = url & “?”
end if

if (total_pages > 10) then
if (total_pages > 3) then
intMaxPages = 3
else
intMaxPages = total_pages
end if

for intPaginI = 1 to intMaxPages
if (intPaginI = current_page) then
strPages = strPages & “” & intPaginI & “
else
strPages = strPages & “” _fcksavedurl=””>” & intPaginI & “
end if
if (intPaginI < intMaxPages) then
strPages = strPages & “, “
end if
next

if (total_pages > 3) then
if ((current_page > 1) and (current_page < total_pages)) then
if (current_page > 5) then
strPages = strPages & ” … “
else
strPages = strPages & “, “
end if

if (current_page > 4) then
intMinPages = current_page
else
intMinPages = 5
end if

if (current_page < total_pages – 4) then
intMaxPages = current_page
else
intMaxPages = total_pages – 4
end if

for intPaginI = intMinPages – 1 to intMaxPages + 1
if (intPaginI = current_page) then
strPages = strPages & “” & intPaginI & “
else
strPages = strPages & “” _fcksavedurl=””>” & intPaginI & “
end if
if (intPaginI < intMaxPages + 1) then
strPages = strPages & “, “
end if
next

if (current_page < total_pages – 4) then
strPages = strPages & ” … “
else
strPages = strPages & “, “
end if
else
strPages = strPages & ” … “
end if

for intPaginI = total_pages – 2 to total_pages
if (intPaginI = current_page) then
strPages = strPages & “” & intPaginI & “
else
strPages = strPages & “” _fcksavedurl=””>” & intPaginI & “
end if
if (intPaginI < total_pages) then
strPages = strPages & “, “
end if
next
end if
else
for intPaginI = 1 to total_pages
if (intPaginI = current_page) then
strPages = strPages & “” & intPaginI & “
else
strPages = strPages & “” _fcksavedurl=””>” & intPaginI & “
end if
if (intPaginI < total_pages) then
strPages = strPages & “, “
end if
next
end if

do_pagination = strPages
end function

isAlphaNumeric:

cú pháp:

boolean = IsAlphaNumeric(string)

Ví dụ sử dụng:

<%
‘ IsAlphaNumeric returns True
response.write IsAlphaNumeric(“This Thing”)
response.write IsAlphaNumeric(“This_Thing 155088_45515”)
response.write IsAlphaNumeric(“Some_Other Thing_25”)
response.write IsAlphaNumeric(17968)

‘ IsAlphaNumeric returns False
response.write IsAlphaNumeric(“(37.8)”)
response.write IsAlphaNumeric(“37.8A[“)
response.write IsAlphaNumeric(“ABSD= acscrrrw!”)
response.write IsAlphaNumeric(“11200-5432”)
%>

Mã của hàm:

<%
Private Function IsAlphaNumeric(byVal string)
dim regExp, match, i, spec
For i = 1 to Len( string )
spec = Mid(string, i, 1)
Set regExp = New RegExp
regExp.Global = True
regExp.IgnoreCase = True
regExp.Pattern = “[A-Z]|[a-z]|s|[_]|[0-9]|[.]”
set match = regExp.Execute(spec)
If match.count = 0 then
IsAlphaNumeric = False
Exit Function
End If
Set regExp = Nothing
Next
IsAlphaNumeric = True
End Function
%>