Textarea max rows and max characters per row

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Ferris

    Textarea max rows and max characters per row

    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.
  • lallous

    #2
    Re: Textarea max rows and max characters per row

    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...
    --
    Elias
    "Greg Ferris" <gregory@ferris .net> wrote in message
    news:8879826f.0 401160133.25d75 08e@posting.goo gle.com...[color=blue]
    > 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.[/color]


    Comment

    • Greg Ferris

      #3
      Re: Textarea max rows and max characters per row

      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


      "lallous" <lallous@lgwm.o rg> wrote in message news:<bu8cvj$ej 3o0$1@ID-161723.news.uni-berlin.de>...[color=blue]
      > 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...
      > --
      > Elias
      > "Greg Ferris" <gregory@ferris .net> wrote in message
      > news:8879826f.0 401160133.25d75 08e@posting.goo gle.com...[color=green]
      > > 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.[/color][/color]

      Comment

      Working...