471,073 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

Filtering Textarea Input?

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
4 4737
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
"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
"|-|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
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.

Similar topics

4 posts views Thread by Csaba Gabor | last post: by
4 posts views Thread by Chris Sharman | last post: by
5 posts views Thread by Jesper Rønn-Jensen | last post: by
2 posts views Thread by danielboendergaard | last post: by
2 posts views Thread by dennis.sprengers | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.