Connecting Tech Pros Worldwide Help | Site Map

libraries or functions to escape quotes, tabs, etc.

christopher.tokar@gmail.com
Guest
 
Posts: n/a
#1: Jan 5 '07
Hello,
I was wondering if there are any proper, robust libraries or
functions/methods that I don't know of that will escape all the
problematic characters such as single quotes and tabs. I find myself
writing
x = x.replace(/'/g,"\\'"); and the reverse over and over again.
Shouldn't Javascript have a built in method to do this? I know of the
escape() function but I am not sure if this is more for urls. What is
the real world way of storing such an "escaped" variable in a database
that will later be read into a javascript variable? :-/
Maybe one could use escape() and unescape() in some way, but some
expert probably could answer this in a snap.
Thanks!
Chris

Randy Webb
Guest
 
Posts: n/a
#2: Jan 6 '07

re: libraries or functions to escape quotes, tabs, etc.


christopher.tokar@gmail.com said the following on 1/5/2007 10:22 AM:
Quote:
Hello,
I was wondering if there are any proper, robust libraries or
functions/methods that I don't know of that will escape all the
problematic characters such as single quotes and tabs. I find myself
writing
x = x.replace(/'/g,"\\'"); and the reverse over and over again.
Write a function that does it for you then:

function fixIt(x){
x = x.replace(/'/g,"\\'");
return x
}

myString = fixIt(myString)

And then you have your own library for it.
Quote:
Shouldn't Javascript have a built in method to do this? I know of the
escape() function but I am not sure if this is more for urls. What is
the real world way of storing such an "escaped" variable in a database
that will later be read into a javascript variable? :-/
Having the server "fix it" before saving it and then sending it back to
the client.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Closed Thread