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:

Use java script file client side and server side at a time in node js

30-07-2017 node js include call javascript

How to submit form using javascript or jquery.

16-04-2017 javascript jquery submit form

Sanitization in java sript

14-03-2017 sanitization java script

Navigate to another page using java script

06-03-2017 javascript redirection navigation

How to change background color and color to the text using javascript

27-02-2017 css javascript colors