Textarea max rows and max characters per row

G

Greg Ferris

I have read a number of posts with techniques for limiting the max
number of characters entered into a textarea, but I'm looking for some
advice on how to limit the number of rows and the number of characters
per row.

Basically, I need to allow users to enter up to 5 rows of data with up
to 40 characters per row, regardless of whether or not the user has
explicitly entered any line breaks. I also need to consider where to
break off each line without breaking in the middle of a word.

Any advice would be greatly appreciated.
 
L

lallous

Hello,

Basically, row1 and row2 are seperated by a new line character ("\n").
Word wrapping visually shows multiple rows however it is still the same row.

So to limit number of rows, simply count how much new line characters there
are.

To limit characters per row, simply scan each row and check its length.

<script>
t = "hello\n" +
"world\n";

lines = t.split('\n');
</script>

This script will create an array which holds every line...
 
G

Greg Ferris

Elias,
Thank you for the help. The issue isn't what happens when a user
enters a line break - I can detect that pretty easily. The issue is
how I treat an entry WITHOUT line breaks. In other words, if the user
types continuously, I need to then programatically create line breaks
for the user (instead of just wrapping), still following the rules
that there can only be five rows and 50 characters per row. Further,
when creating these breaks, I want to be sure that I'm not doing it in
the middle of a word.

Thanks,
Greg
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top