0

we run a web2print solution, that some people fill out a form to update some artwork.

The problem is some users paste in text from word or other programs, and get weird dashes, spaces etc that aren't a part of normal keyboard input.

What we want to do is restrict the input to all the "normal" keyboard keys, not the unmapped character codes. How do we do this?

Many thanks,

b

Brettski
  • 1,061
  • 2
  • 12
  • 25
  • You will be doing this on the server side as well, right? JavaScript (including jQuery) runs client-side, and the [clients](http://stackoverflow.com/questions/162159/javascript-client-side-vs-server-side-validation) [are](http://stackoverflow.com/questions/3531968/why-is-client-side-validation-a-security-risk-as-opposed-to-server-side-validatio) [not to](http://stackoverflow.com/questions/1717746/can-user-disable-javascript-at-client-side-is-it-possible) [be trusted](http://stackoverflow.com/questions/1516852/client-side-logic-or-server-side-logic). – David Thomas Mar 27 '11 at 23:24

2 Answers2

0

I would create an array or something of all keyboard keys and then remove all chars that don't match.

mattsven
  • 22,305
  • 11
  • 68
  • 104
0

You can use encodeURIComponent(value) function. It outputs safe coded UTF8 strings.

mterhal
  • 1
  • 1
  • That is really not related at all to the question. The question is not about how to encode data. It is how to replace fancy dashes like `—` by `-`, or fancy quotes like `« » “` by `"`. All the fancy characters I've used here are already UTF-8 anyway. But the point is that they are all in the sets of characters the OP want to accept in a form (for unspecified internal reason of them, probably related to what is done with those forms afterwards) – chrslg Feb 08 '23 at 22:34