RIRedinPA Posted August 18, 2008 Share Posted August 18, 2008 Does Javascript have something like this, that'll make a string compliant for mysql (i.e escape apostrophes, quotes, etc. Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 18, 2008 Share Posted August 18, 2008 There's only escape() method, but it won't suffice for mysql. You'd have to do some replacing by yourself. Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 18, 2008 Share Posted August 18, 2008 There shouldn't be any need to make a string db safe on the client-side. The data has to go through server-side code before it can go to the database. Can you elaborate on why you want to handle this through javascript? Quote Link to comment Share on other sites More sharing options...
RIRedinPA Posted August 18, 2008 Author Share Posted August 18, 2008 It doesn't necessarily have to be db safe, I'm passing a string to javascript and it is breaking on apostrophes and stuff. Escape seems to take care of it for me. Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 18, 2008 Share Posted August 18, 2008 It is actually pretty simple to write one. Just use regex to find an replace any characters you don't want: function escape_string(str) { return str.replace(/['\"]/g, ""); } That would just remove all single and double quotes, but you can have it do whatever you want. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.