Sanitization in java sript

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>";


You might also like:

Example for Conditional Operator in php

16-04-2017 php Conditional Operator example

How to upload file by using request module

18-03-2017 request module node js

Filter for insert HTML in Angular Js

06-03-2017 filter show html angular js html

Filters for convert text to camel case in Angular Js

05-03-2017 angularjs camelcase filters

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

27-02-2017 onchange events dropdown javascript functions