1. Anti-injection of URL address:
//Filter URL illegal SQL characters 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("Do not enter illegal characters"); location.href=sUrl.replace(sQuery,""); }2. Enter text box to prevent injection:
/Prevent SQL injection 2function AntiSqlValid(oField ) 3{ 4 re= /select|update|delete|exec|count|'|"|=|;|>|<|%/i; 5 if ( re.test(oField.value) ) 6 { 7 //alert("Please do not enter special characters and SQL keywords in the parameters!"); //Note the Chinese garbled 8 oField.value = "; 9 oField.className="errInfo"; 10 oField.focus(); 11 return false; 12 }Add the following method to the input text box that requires anti-injection:
txtName.Attributes.Add("onblur", "AntiSqlValid(this)");// Prevent Sql script injection
The above article sharing two simple JS code to prevent SQL injection is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.