Filtering Textarea Input?

R

Ralph Freshour

I want to filter textarea input to the following characters:

A-Za-z0-9._

How can I do this in JS and should this be done on a keyup or keydown
press? When the user presses a char not in this list, I want nothing
to happen in the textarea.

Thanks...
 
L

Lee

Ralph Freshour said:
I want to filter textarea input to the following characters:

A-Za-z0-9._

How can I do this in JS and should this be done on a keyup or keydown
press? When the user presses a char not in this list, I want nothing
to happen in the textarea.

You shouldn't do that at all. If the user presses a key and
nothing happens, he's not going to say to himself "Oh, that
must have been an illegal character, I'll try try another".
He's going to say, "Dammit, this browser is acting up again!
I had better close this page and restart and hope I can find
my way back to this site".

Audit the input onchange or onsubmit.
 
L

Lasse Reichstein Nielsen

|-|erc said:
It's a valid technique imo, I just did some validate code today for
a numeric field, most databases you type letters into a numeric
field and thats when they restart.

Valid, yes. Problematic, yes too.

Can you use tab to leave the input field? If not, that is a major
usability no-no. Generally, cancelling the user's action without
a warning is bad.

Who cares what databases do? You should validate the input on the
server, if there are any inputs that are problematic. You can validate
on the client too to save the user a roundtrip to the server, but
the easiest, and least intrusive, way is to do it in the onsubmit
handler.

/L
 
L

Lee

|-|erc said:
It's a valid technique imo, I just did some validate code today for a numeric
field,
most databases you type letters into a numeric field and thats when they
restart.

Restricting a text field to digits is not as bad as restricting
a textarea as the OP suggests, but it's still a bad idea.
Audit the value afterwards and tell the user what's wrong.

I assume you audit the data on the server side, too. Otherwise,
I can send whatever garbage I like into your database.
 

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,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top