Home  >  Article  >  Web Front-end  >  防止xss和sql注入:JS特殊字符过滤正则_javascript技巧

防止xss和sql注入:JS特殊字符过滤正则_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:36:283337browse
复制代码 代码如下:

function stripscript(s)
{
var pattern = new RegExp("[%--`~!@#$^&*()=|{}':;',\\[\\]./?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")        //格式 RegExp("[在中间定义特殊过滤字符]")
var rs = "";
for (var i = 0; i  rs = rs+s.substr(i, 1).replace(pattern, '');
}
return rs;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn