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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:46:00+00:00 2026-06-09T14:46:00+00:00

Trying to allow a user to type into a textarea, but if a certain

  • 0

Trying to allow a user to type into a textarea, but if a certain word is seen, I would like the cursor to stop until that word is removed.

I have finding the word, but I am unable find a way to have the cursor stop.

Any ideas on how i would do this in javascript

 $(function() {
            $('#ideacomment').bind('keyup', function(e){
                var characterLimit = 300;
                charactersUsed = $(this).val().length;

                if(charactersUsed > characterLimit){
                    charactersUsed = characterLimit;
                    $(this).val($(this).val().substr(0, characterLimit));
                    $(this).scrollTop($(this)[0].scrollHeight);
                }
                var charactersRemaining = characterLimit - charactersUsed;
                $('#remainingCharacters').html(charactersRemaining);

                 var words = $('#ideacomment').val().split(/\b[\s,\.-:;]*/);
                 var wordcount = words.length;
                 var nonewords = new Array("f**k", "you");
                 var nonewordcount = nonewords.length;
                //console.log(nonewordcount + ' is the count');

                for(var i = 0; i < wordcount; i++) {

                    for(var t = 0; t < nonewordcount; t++) {
                        if(words[i] == nonewords[t]) {
                            message('No swearing please! <br><br> This post will not succeed!<br><br> Please remove it before you continue!', '430');
                            }
                        }
            }
            });


      });

The code above counts the number of chars and also checks each word. Would I would like and I have tried without success is have it as if it ran out of space. But i have been unable to make it happen using the same code the limiter?

This is the new code. Still not working though:

        $(function() {
            $('#ideacomment').bind('keyup', function(e){
                var characterLimit = 300;
                charactersUsed = $(this).val().length;

                if(charactersUsed > characterLimit){
                    charactersUsed = characterLimit;
                    $(this).val($(this).val().substr(0, characterLimit));
                    $(this).scrollTop($(this)[0].scrollHeight);
                }
                var charactersRemaining = characterLimit - charactersUsed;
                $('#remainingCharacters').html(charactersRemaining);

                 var nonewords = new Array("hey", "you");
                 var nonewordcount = nonewords.length;
                 for(var t = 0; t < nonewordcount; t++) {
                     if ($(this).val().indexOf(nonewords[t]) != -1) {
                        message('No swearing please! <br><br> This post will not succeed!<br><br> Please remove it before you continue!', '430');
                         var keycode = e.charCode || e.keyCode;
                            console.log(keycode);
                            if (keycode !== 8 && keycode !== 46)
                                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-09T14:46:01+00:00Added an answer on June 9, 2026 at 2:46 pm

    You could check which key is being pressed, and block it if it is not a Backspace or Delete. Here is a simplified example:

    $(function() {
        $('#textbox').keydown(function(e) {
            if ($(this).val().indexOf('test') != -1) {
                var keycode = e.charCode || e.keyCode;
                if (keycode !== 8 && keycode !== 46)
                    return false;
            }
        });
    });​
    

    jsFiddle Demo

    Since you already seem to have the text-checking and notification part, all you’re really missing is just the keypress-blocking part.

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

Sidebar

Related Questions

I'm trying to allow a user to type an artist into a text box
I am trying to allow users to enter Hebrew characters into certain fields in
I'm trying to create a script that would allow the user to upload images
So I'm writing an application that would allow a user to create a type
So I'm trying to add some ability to my project to allow user-defined properties
I trying to pomp showPermissionDialog for allow the user to post something in a
I am trying to set up a page that will allow the user to
I'm trying to modifty the Flex Tree control to allow a user to select
i'm trying to add some navigation arrows which allow the user to go to
I am trying to create a ListView with CheckBox's...Th ListView should allow the user

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.