473,378 Members | 1,066 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 4800
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Csaba Gabor | last post by:
What I'd like to do is to be able to set the font of a textarea element to the same font that another element is using (say, for example, an <INPUT type=text ...> element, but if that's a no go,...
4
by: Chris Sharman | last post by:
I haven't specified fonts, leaving the user to have their chosen font. However, different tags render in different default fonts: text, input, & textarea all different from one another. I guess...
5
by: Jesper Rønn-Jensen | last post by:
I have a textarea that must be limited to 70 characters. No big deal -- at least so I thought. * Textarea must not exceed 70 characters * Exceeding content must be cut off * Must work on input by...
2
by: danielboendergaard | last post by:
Hey Im making a homepage in php. I use a html form to put data into mysql and i want to make some buttons which inserts user input values into a textarea. I have used a button like this: <input...
3
by: Syswatch | last post by:
Hi out there... I am pretty new to javascript, and is looking for some help here. I have a problem, I need a small javascript, which checks if there is any text in my textarea, and if it is NOT...
16
by: Jen | last post by:
Hi. I have this problem that I think should be easy but have been struggling with this for days. I have a list based on a recordset from a database. This list consists of records meeting a certain...
2
by: dennis.sprengers | last post by:
Ik ben bezig met een eigen UBB editor. Als iemand aan het typen is, zorgt CTRL-B voor een \-tag en nogmaals CTRL-B voor een \ tag. Als je eerst een selectie maakt en dan CTRL-B drukt, wordt de...
1
by: nagamalli26 | last post by:
hai iam new php. i am creating admin side. i wrote this, phpcode: <?php //include_once("config.php"); $con=mysql_connect("localhost","root",""); mysql_select_db("happysalary"); ?>
5
by: alf8kitty | last post by:
Hello, I have a form that allows a user to submit notes in a textarea. <td><textarea name="Notes" value="" ROWS=3 COLS=35></textarea></td> The notes get sent to the MySQL database correctly...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.