libraries or functions to escape quotes, tabs, etc.

  • Thread starter christopher.tokar
  • Start date
C

christopher.tokar

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
 
R

Randy Webb

(e-mail address removed) said the following on 1/5/2007 10:22 AM:
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.
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top