代碼示例 本代碼示例包含了一個函數(shù),它可刪除發(fā)送至該函數(shù)的字符串中的可能有害的字符。在上面的兩個示例中,指定代碼頁以確保正確地編碼。下面的示例使用的是 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; } %>