Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7968567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:05:51+00:00 2026-06-04T07:05:51+00:00

I have been searching all weekend for the solution to this quandry and have

  • 0

I have been searching all weekend for the solution to this quandry and have yet to find a solution that works correctly. What I am trying to acchieve is to limit the number of charatcers per line in a textarea – not limiting them identically, but a different number of characters per line of my choosing.

For Example:

  1. I want to have only 4 lines in my textarea
  2. Line 1,2 and 3 will be limited to 24 characters
  3. Line 4 will have an unlimited number of characters

Is this possible with a textarea, or is there another way of doing i with a Div or something. I do realise that this has in all likelihood been covered before, but to find an actual working script that covers this criterium has proved extremely difficult and I don’t have the kind of skill it takes to acchieve these results.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:05:52+00:00Added an answer on June 4, 2026 at 7:05 am

    Below is a sample snapshot of the problem that you’re trying to solve:

    • 4 lines in the textarea (Limit this on the textarea itself with rows=”4″)
    • Lines 1, 2, and 3 are limited to 24 characters
    • Line 4 will have an unlimited number of characters

    Snapshot of the textarea:

    123456789012345678901234
    123456789012345678902333
    232323232323232323323232
    23232323232323232323236464536543654643
    

    JavaScript:

    $('#your-input').keypress(function() {
         var text = $(this).val();
         var arr = text.split("\n");
    
         if(arr.length > 5) {
             alert("You've exceeded the 4 line limit!");
             event.preventDefault(); // prevent characters from appearing
         } else {
             for(var i = 0; i < arr.length; i++) {
                 if(arr[i].length > 24 && i < 3) {
                     alert("Length exceeded in line 1, 2, or 3!");
                     event.preventDefault(); // prevent characters from appearing
                 }
             }
         }
    
         console.log(arr.length + " : " + JSON.stringify(arr));
    });
    

    This can be accomplished using a keypress event. When the keypress event fires, get the current value of the textbox and split the value into an array using the \n line break character as a delimiter.

    • The length of the array tells you how many lines you have. If you’ve exceeded those lines, we fire an alert.
    • The length of each individual string inside the array represents the length of each line. We use a for loop to check the first 3 lines. If we exceed the length of 24, we fire an alert.
    • We ignore the last iteration of the loop, since we aren’t concerned with the length of the last line.

    This is not designed to be a complete solution, but this will definitely get you started and provide you with something that you can modify to suit your needs. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been searching all day and can't find a solution to this... I have
I have been searching all over the Internet, but did not find that exact
I have been searching all over but I can't find any answer to this.
I have been searching this since yesterday and still nothing. From all that researching
I have been searching the web and all over stackoverflow, but yet couldn't find
I have been searching all over and i cant seem to find a solution.
I have been searching all over the web trying to find an example of
I have been searching for this all over the internet, this site claims that
I have been searching for a solution to this and so far found nothing
I have been searching for this. All the related Java APIs are worked on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.