代码示例
本代码示例包含了一个函数,它可删除发送至该函数的字符串中的可能有害的字符。在上面的两个示例中,指定代码页以确保正确地编码。下面的示例使用的是 Microsoft Visual Basic® Scripting Edition(VBScript):
<%@ LANGUAGE="VBScript" %>
<%
Response.CodePage = 1252
Response.Write("Hello, " & RemoveBadCharacters(Request.Form("UserName")))
Response.Write("<BR>This is why you received an error:")
Function RemoveBadCharacters(strTemp)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = "[^\s\w]"
regEx.Global = True
RemoveBadCharacters = regEx.Replace(strTemp, "")
End Function
%>
下面的示例使用的是 Microsoft JScript®:
<%@ LANGUAGE="JScript" %>
<%
Response.CodePage = 1252;
Response.Write("Hello, " + RemoveBadCharacters(Request.Form("UserName")));
Response.Write("<BR>This is why you received an error:");
function RemoveBadCharacters(strTemp) {
strTemp = strTemp.replace(/[^\s\w]/g,"");
return strTemp;
}
%>
摘自网海之贝
本文地址:http://com.8s8s.com/it/it7730.htm