SoFunction
Updated on 2025-03-03

Share two simple JS code to prevent SQL injection

Address anti-injection:

//Filter URL illegal SQL charactersvar sUrl=(); 
var sQuery=(("=")+1); 
re=/select|update|delete|truncate|join|union|exec|insert|drop|count|'|"|;|>|<|%/i; 
if((sQuery)) 
{ 
  alert("Do not enter illegal characters"); 
  =(sQuery,""); 
} 

2. Enter text box to prevent injection:

/preventSQLinjection 
 2function AntiSqlValid(oField ) 
 3{ 
 4  re= /select|update|delete|exec|count|'|"|=|;|>|<|%/i; 
 5  if ( () ) 
 6  { 
 7  //alert("Please do not enter special characters and SQL keywords in the parameters!"); // Pay attention to Chinese garbled code 8   = "; 
 9  ="errInfo"; 
10  (); 
11  return false; 
12  } 

Add the following method to the input text box that requires anti-injection:

("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 me more.