JS code to prevent SQL injection method (super simple) _javascript tips

Source: Internet
Author: User
Tags sql injection

Below through two aspects to introduce JS code to prevent SQL injection method, very simple and practical, interested friends under the reference bar!

1.URL address anti-injection:

Filter URL illegal 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 illegal characters");
Location.href=surl.replace (Squery, "");
}

2. Input text box anti-injection:

/Prevent SQL injection

function Antisqlvalid (Ofield)
{
re=/select|update|delete|exec|count| ' | ' | =|;| >|<|%/ i;
if (Re.test (ofield.value))
{
//alert ("Please do not enter special characters and SQL keywords in the parameters!") "); Note Chinese garbled
ofield.value = ";
Ofield.classname= "Errinfo";
Ofield.focus ();
return false;
}

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

 
 

About the JS code to prevent SQL injection method small series to introduce so many people, I hope to help you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.