Just a string. Add \' to it every time there is a single quote.
The backslash ( "\" ) character is a special escape character used to indicate other special characters such as new lines ( \n ), tabs ( \t ), or quotation marks ( \" ). If you want to include a backslash character itself, you need two backslashes or use the @ verbatim string: "\\Tasks" or @"\Tasks" .
replace
works for the first quote, so you need a tiny regular expression:
str = str.replace(/'/g, "\\'");
Following JavaScript function handles ', ", \b, \t, \n, \f or \r equivalent of php function addslashes().
function addslashes(string) { return string.replace(/\\/g, '\\\\'). replace(/\u0008/g, '\\b'). replace(/\t/g, '\\t'). replace(/\n/g, '\\n'). replace(/\f/g, '\\f'). replace(/\r/g, '\\r'). replace(/'/g, '\\\''). replace(/"/g, '\\"'); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With