I would like to take a string that the user will enter to a text box in a form and turn it into a javascript literal. So I’d, for instance, turn the ” character into \”.
Is there any complete list of characters that would need to be escaped?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You only need to escape your delimiter and/or whatever enclosing quotes you choose (escape double quotes if you enclose your string in double, escape single otherwise).
If you’re going to render it as HTML, you may wnat to convert them to entities (e.g.
& -> &)