您的位置:首页 > 编程语言 > ASP

asp中用正则表达式过滤字符,避免注入攻击

2007-08-09 18:24 323 查看
' ============================================
' 正则表达式
' 参数patrn 规则
' 参数strng 字符
' 常用过滤纯数字ID 方法 RegExpStr("[0-9]", id)
' ============================================
Function RegExpStr(patrn, strng)
Dim regEx, Match, Matches ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分字符大小写。
regEx.Global = True ' 设置全局可用性。
Set Matches = regEx.Execute(strng) ' 执行搜索。
For Each Match in Matches ' 遍历匹配集合。
'RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value
Next
RegExpStr = RetStr
End Function

用正则表达式过滤id
newsid = RegExpStr("[0-9]", Request.QueryString("newsid"))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: