By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

Filtering Textarea Input?

P: n/a
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...

Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

Jul 20 '05 #2

P: n/a
"Lee" <RE**************@cox.net> wrote
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.


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.

Herc

Jul 20 '05 #3

P: n/a
"|-|erc" <us*************@wwwadamskingdom.com> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

P: n/a
Lee
|-|erc said:

"Lee" <RE**************@cox.net> wrote
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.


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.

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.