Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3601134
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:35:00+00:00 2026-05-18T20:35:00+00:00

I have a bunch of forms that have various input elements. I want to

  • 0

I have a bunch of forms that have various input elements. I want to sanitize these on the server side (yes, I’m using server-side JavaScript) to use these inputs as parameters, and prevent special characters to be malformed.

Before you go, like “this belongs not in the realm of JavaScript”, etc., etc.

I am using a multi-million licensed software solution, that well has JavaScript but apparently has no standard functions like this out of the box. So, whatever I am using, I can assure you that you probably have never touched it or heard of it. And it supports server side javascript, because well, the language is cool.

My first objective is to sanitize data before it goes in the database, and I just love the way for example how Ruby labels foreign data: tainted. And I rather have no tainted data. So I could google and copy paste some poor regex from here and there, and I got some sad example. However, I would like to have a function that would be said “well, that takes off 70% of the possible stuff from that data and a pretty darn good sanitize”.

Basically a string from these elements should be escaped and I assume best practices are already existing for this wish of mine.

function sanitize(myString) { ... ; return myString }

How can I escape symbols like ‘#!? and other special characters and how i can i get them back in reverse? I am aware of the JavaScript escape method, but I want to know if a function is already debugged and public available before I re-invent the wheel.

I considered:
– JavaScript Escape
– Base64 Encoding
– Regex

I just rather ask the people who have written such functions before.

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:35:01+00:00Added an answer on May 18, 2026 at 8:35 pm

    See update below

    You’re reinventing the wheel. Whatever you’re using to talk to your database should have some kind of “prepared statement” concept. In Java it’s literally the PreparedStatement class, but essentially any database access system should have something similar. You use these so that you’re not building up SQL statements as strings. So for instance, conceptually:

    preparedStatement = prepare("insert into mytable (id, name) values (?, ?)")
    preparedStatement.setField(0, theId);
    preparedStatement.setField(1, theName);
    

    Not:

    statement = "insert into mytable (id, name) values ('" + theId + "', '" + theName + "')"
    

    …which is asking for injection attacks.

    The “prepared statement” concept centralizes escaping to the database link layer, which is well-prepared to handle it. If you tell people what you’re using to access your database, they’ll be able to point you at the relevant mechanism. See below.

    Just for the avoidance of doubt: You’re doing this escaping on the server, right? I mean, that’s how I read it, you’ve actually said “I want to sanitize these on the server side…”. But just in case you were thinking of doing it client-side: You can’t. Nothing, absolutely nothing, that the client-side sends you can be trusted, as it can be faked. You must do this server-side.


    Update: You’ve commented that you’re using Rhino in an application server. Excellent! Then just PreparedStatement and let your JDBC driver handle it for you. (For non-Java lurkers: Rhino is JavaScript for the Java VM. It’s brilliant.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of forms that have various input elements. I want to
I have a bunch of forms that I need to put in a list
I have a bunch of urls that toggle user settings I would like to
The Problem: I have a forms project which instantiates a class that is defined
I am trying to DRY up a bunch of forms code that has a
We have a couple of winforms applications that host a bunch of icons in
I've looked at the various options that seem to be available on the .NET
Note: This is .NET regular expressions. I have a bunch of text, from which
Basically I want to load a HTML document and using controls such as multiple
I am recently working on windows forms with visual C# and I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.