Sanitization in java sript

sanitization
java script

Basically sanitization is used for escaping special characters while inserting into database.

function mysql_real_escape_string (str) {
    return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
        switch (char) {
            case "\0":
                return "\\0";
            case "\x08":
                return "\\b";
            case "\x09":
                return "\\t";
            case "\x1a":
                return "\\z";
            case "\n":
                return "\\n";
            case "\r":
                return "\\r";
            case "\"":
            case "'":
            case "\\":
            case "%":
                return "\\"+char; // prepends a backslash to backslash, percent,
                                  // and double/single quotes
        }
    });
}

How to this function ?

var template = "<div> Hi Welcome to this example.</div>";
mysql_real_escape_string(template);

 

You might also like:

A Very Big Sum | Javascript | hackerrank

07-05-2020 A Very Big Sum Javascript hackerrank

Compare the Triplets | Javascript | hackerrank.com

07-05-2020 hackerrank.com

How to redirect one page to another page in php

20-03-2017 redirect php

How to insert bulk information into database in single query execution

18-03-2017 insert sql bulk database

How to get drop down value when drop down change using javascript

27-02-2017 onchange events dropdown javascript functions