剥去所有特殊字符

时间:2012-02-14 21:12:15

标签: function vbscript asp-classic

有谁能告诉我如何在ASP(经典)中删除所有特殊字符(<>,/ \'%;()& + - *)?

这就是我所拥有的,但它不起作用。

Function RemoveBad(strTemp)

Dim regEx
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Pattern = "[/\<|\>|\|\'|\%|\;|\(|\)|\&|\+|\-/g]"
RemoveBad = replace(strTemp,regEx.Pattern," ")

End Function

3 个答案:

答案 0 :(得分:4)

为了防止XSS,你只需要这个;

function RemoveBad(strTemp)
    RemoveBad = server.htmlencode(strTemp) 
end function

答案 1 :(得分:2)

使用RegExp.Replace方法:

RemoveBad = regEx.Replace(strTemp, "")

答案 2 :(得分:0)

您可以在函数中使用一系列替换语句


Function RemoveBad(strTemp)  

strTemp = REPLACE( strTemp, Chr(1),  '')
strTemp = REPLACE( strTemp, Chr(2),  '')
strTemp = REPLACE( strTemp, Chr(3),  '')
strTemp = REPLACE( strTemp, Chr(4),  '')
strTemp = REPLACE( strTemp, Chr(5),  '')
strTemp = REPLACE( strTemp, Chr(6),  '')
strTemp = REPLACE( strTemp, Chr(7),  '')
strTemp = REPLACE( strTemp, Chr(8),  '')
strTemp = REPLACE( strTemp, Chr(9),  '')
strTemp = REPLACE( strTemp, Chr(10), '')
strTemp = REPLACE( strTemp, Chr(11), '')
strTemp = REPLACE( strTemp, Chr(12), '')
strTemp = REPLACE( strTemp, Chr(13), '')
strTemp = REPLACE( strTemp, Chr(14), '')
strTemp = REPLACE( strTemp, Chr(15), '')
strTemp = REPLACE( strTemp, Chr(16), '')
strTemp = REPLACE( strTemp, Chr(17), '')
strTemp = REPLACE( strTemp, Chr(18), '')
strTemp = REPLACE( strTemp, Chr(19), '')
strTemp = REPLACE( strTemp, Chr(20), '')
strTemp = REPLACE( strTemp, Chr(21), '')
strTemp = REPLACE( strTemp, Chr(22), '')
strTemp = REPLACE( strTemp, Chr(23), '')
strTemp = REPLACE( strTemp, Chr(24), '')
strTemp = REPLACE( strTemp, Chr(25), '')
strTemp = REPLACE( strTemp, Chr(26), '')
strTemp = REPLACE( strTemp, Chr(27), '')
strTemp = REPLACE( strTemp, Chr(28), '')
strTemp = REPLACE( strTemp, Chr(29), '')
strTemp = REPLACE( strTemp, Chr(30), '')
strTemp = REPLACE( strTemp, Chr(31), '')

' Add as many replace statements as you need

End Function