1. URL address injection prevention:
//过滤URL非法SQL字符 var sUrl=location.search.toLowerCase(); var sQuery=sUrl.substring(sUrl.indexOf("=")+1); re=/select|update|delete|truncate|join|union|exec|insert|drop|count|'|"|;|>|<|%/i; if(re.test(sQuery)) { alert("请勿输入非法字符"); location.href=sUrl.replace(sQuery,""); }
2. Input text box anti-injection:
/防止SQL注入 2function AntiSqlValid(oField ) 3{ 4 re= /select|update|delete|exec|count|'|"|=|;|>|<|%/i; 5 if ( re.test(oField.value) ) 6 { 7 //alert("请您不要在参数中输入特殊字符和SQL关键字!"); //注意中文乱码 8 oField.value = "; 9 oField.className="errInfo"; 10 oField.focus(); 11 return false; 12 }
Add the following method to the input text box that needs to be protected against injection:
txtName.Attributes.Add("onblur", "AntiSqlValid(this)");//Prevent Sql script injection
The above article sharing two simple JS codes to prevent SQL injection is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Script Home more.