Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: (input and output)

there is a textarea in a form that people seem to enjoy entering 5 spaces in between each line they type. this causes a problem when i print the info on paper that has preprinted info on it. Unlike the normal text box, MAXLENGTH is not an attribute of a textarea. Therein lies my problem

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do you limit textarea of a form
by ZZamboni (Curate) on May 25, 2000 at 03:11 UTC
    Or if you want to remove blank lines:
    s/\n{2,}/\n/g;
    If you want to clump everything into a single line (maybe for reformatting it yourself, see Text::Wrap or my Nicely format a list or a string snippet):
    s/\s+/ /g;
    If you want to cut it to the first 5 non-empty lines:
    $text=join("\n",(split(/\n+/,$text))[0..4])
    I don't think there is an HTML attribute to restrict the number of lines in a TEXTAREA.

    --ZZamboni

Re: How do you limit textarea of a form
by reptile (Monk) on May 25, 2000 at 00:15 UTC

    A possible perl solution is removing some of the newlines, like:

    s/\n{3,}/\n\n/g;

    which will replace three or more newlines in a row with two (two to preserve double-spacing of paragraphs).

Re: How do you limit textarea of a form
by newrisedesigns (Curate) on Dec 19, 2002 at 14:59 UTC

    In the text of the page, put "X character limit." Then $text = substr($text, 0, X)

    You can also add the following as a guide to your form-submitters.

    <input value="X" size="3" name="msgCL" disabled> <script language="JavaScript"> <!-- var supportsKeys = false function tick() { calcCharLeft(document.forms[0]) if (!supportsKeys) timerID = setTimeout("tick()",200) } function calcCharLeft(sig) { clipped = false maxLength = 200 //Change this. if (document.creator.signature.value.length > maxLength) { document.creator.signature.value = document.creator.signature. +value.substring(0,maxLength) charleft = 0 clipped = true } else { charleft = maxLength - document.creator.signature.value.length } document.creator.msgCL.value = charleft return clipped } tick(); //--> </script>

    Hope this helps

Re: How do you limit textarea of a form
by Anonymous Monk on Jul 01, 2002 at 16:55 UTC
    We used javascript to count the number of characters in the textarea box. If the number was too large, we disallowed form entry with a user alert.

    Originally posted as a Categorized Answer.