Share two simple JS Code sections to prevent SQL injection and two jssql injection sections.
1. URL address anti-injection:
// Filter out Invalid URL. The SQL character 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 invalid characters"); location. href = sUrl. replace (sQuery ,"");}
2. Enter the text box to prevent injection:
/Prevent SQL injection 2 function 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 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 for anti-injection:
TxtName. Attributes. Add ("onblur", "AntiSqlValid (this)"); // prevents SQL Script Injection
The above two simple sections of JavaScript code to prevent SQL injection are all the content shared by the editor. I hope to give you a reference, and I hope you can provide more support to the customer center.