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 7900673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:01:42+00:00 2026-06-03T09:01:42+00:00

I have the following function to get the value in a textarea with the

  • 0

I have the following function to get the value in a textarea with the id #posttext and to call a function to post something.

I do not want the user to be able to type in more than one line break in a row. How can I prevent that?

Here’s the code:

//Post something
$('#postDiv').on('keydown', '#posttext', function(e) {
if (e.which==13 && !e.shiftKey && $('#posttext').val()!=' Post something...') {

//This is what I tried to prevent a user from inserting more than one br in a row
var last = false;

var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) {
    if (last) { e.preventDefault(); }
    last=true;
}else{
    last=false;
}

//If not currently loading and enough text typed in, submit
if($('#imageFeedback').html()!=' | Loading...' && $('#posttext').val().length>15){

    //Say that it is loading
    $('#imageFeedback').css('color','black').css('font-weight','normal').html(' | Loading...');

    //Call function to post
    post($(this));
    return false;
}
}
});
  • 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-03T09:01:43+00:00Added an answer on June 3, 2026 at 9:01 am

    It would be much better if you simply removed duplicate linebreaks later, e.g. with this regex: s/\n{2,}/\n/g

    However, to do what you want, simply remove duplicate newlines onkeyup

    $('#postDiv').on('keyup', '#posttext', function(e) {
        var val = $(this).val(),
            newval = val.replace(/\n{2,}/g, '\n');
        if(val != newval) {
            $(this).val(newval);
        }
    });
    

    Demo: http://jsfiddle.net/ThiefMaster/WJmhF/

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

Sidebar

Related Questions

I have the following code in html, I cannot get the Function call back
I have the following code: <form action= method=get onsubmit=doRequest($('word').value); $('word').value=''; return false;> <input type=text
I have the following code: dijit.byId('patient').onchange(function(event){ var term=dijit.byId('patient').get('value'); patientList.url = .calendar/search-patient?term=+term; patientList.close(); }) What
If I have following in jQuery $(#someId).add(#someOtherId).bind(click, function(e) {... I get the click bound
I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){
I have the following code: Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer) 'first get
I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
I Have the following function. function ChangeDasPanel(controllerPath, postParams) { $.post(controllerPath, postParams, function(returnValue) { $('#DasSpace').hide(slide,
i have following function: function fnGetIdentifiers(id){ $.get( 'getCultureIdentifiers.php?cultureID=' + id, function(data){ if (data.length >
I have the following PowerShell code: function Get-SmoConnection { param ([string] $serverName = ,

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.