Addslashes and Stripslashes |
|
Join the DiscussionIf you are used to programming your server side code using PHP then you have probably used the addslashes() and stripslashes() functions to handle the processing of certain characters such as quotes within input fields. Javascript doesn't come with equivalent functions but you can easily add these functions into Javascript by adding the following code: function addslashes(str) {
str=str.replace(/\\/g,'\\\\'); str=str.replace(/\'/g,'\\\''); str=str.replace(/\"/g,'\\"'); str=str.replace(/\0/g,'\\0'); return str; } function stripslashes(str) { str=str.replace(/\\'/g,'\''); str=str.replace(/\\"/g,'"'); str=str.replace(/\\0/g,'\0'); str=str.replace(/\\\\/g,'\\'); return str; } |

