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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:37:57+00:00 2026-06-11T23:37:57+00:00

I have a form that pop ups for users to leave comments on videos.

  • 0

I have a form that pop ups for users to leave comments on videos. Inside the form where people enter the message there is a profanity filter in place. It works fine and catches the word if it is in the message. My question is if there is a way to highlight the word that is caught so the user can see which one was considered profane?

Here is the message being formed and going through the filter:

    if (context.Request["postform"] == "1")
    {
        ProfanityFilter filter = new ProfanityFilter();

        // IF NEITHER THE MESSAGE OR FIRSTNAME CONTAINS ANY PROFANITY IN THEM
        if (filter.containsProfanity(context.Request["message"]) == false && filter.containsProfanity(context.Request["first_name_submitter"]) == false)
        {
            videomessage myVideoMessage = new videomessage();

            myVideoMessage.video_id = context.Request["video_id"];
            myVideoMessage.first_name_submitter = context.Request["first_name_submitter"];
            myVideoMessage.last_initial_submitter = context.Request["last_initial_submitter"];
            myVideoMessage.message = context.Request["message"];
            myVideoMessage.status = "0";

            myVideoMessage.Save();

            return_success = "1";                
        }
        else
        {
            return_success = "0";
            return_errormessage = "<span>Contains profanity</span>";
        }                
    }

And here is the ProfanityFilter class:

public class ProfanityFilter
{
    // ***********************************************************************
    // CONSTRUCTORS
    public ProfanityFilter()
    {
    }
    // ***********************************************************************



    // ************************************************************************
    // METHOD: containsProfanity
    public bool containsProfanity(string checkStr)
    {
        bool badwordpresent = false;

        string[] inStrArray = checkStr.Split(new char[] { ' ' });

        string[] words = this.profanityArray();

        // LOOP THROUGH WORDS IN MESSAGE
        for (int x = 0; x < inStrArray.Length; x++)
        {
            // LOOP THROUGH PROFANITY WORDS
            for (int i = 0; i < words.Length; i++)
            {
                // IF WORD IS PROFANITY, SET FLAG AND BREAK OUT OF LOOP
                //if (inStrArray[x].toString().toLowerCase().equals(words[i]))
                if( inStrArray[x].ToLower() == words[i].ToLower() )
                {
                    badwordpresent = true;
                    break;
                }
            }
            // IF FLAG IS SET, BREAK OUT OF OUTER LOOP
            if (badwordpresent == true) break;
        }

        return badwordpresent;
    }
    // ************************************************************************




    // ************************************************************************
    // METHOD: profanityArray()
    // METHOD OF PROFANITY WORDS
    private string[] profanityArray()
    {

        string[] words = { // ARRAY OF WORDS };
return words;
}
}

Is there a way to add something in the else to highlight the word? Or even just change its color from black to red?

Thank you in advance!

  • 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-11T23:37:58+00:00Added an answer on June 11, 2026 at 11:37 pm

    The most straightforward way to do it is to replace all occurrances of profane words with markup representing that word, e.g.

    <span class="profane">PUT_THE_WORD_HERE</span>
    

    In your css, include a rule

    span.profane
    

    that provides some sort of visual indication.

    Since you should strive for a separation of concerns, I would not do this markup in ProfanityFilter itself. A slick way to do this would be to have ProfanityFilter provide an event for each string fragment it processes. That callback would provide an indicator as to whether the word is deemed profane or not, and the fragment itself. In the event handler, you would reconstruct the original phrase by appending each event’s fragment, surrounding it with markup if it is profane. That event would also have to receive whitespace and punctuation so that the full original phrase can be re-created.

    Phrase:

    "This website sucks.  Really!"
    

    Events:

    "This", profane: false
    " ", profane: false
    "website", profane: false
    " ", profane: false
    "sucks", profane: true
    ".  ", profane: false
    "Really", profane: false
    "!", profane: false
    

    If you don’t want to get that elaborate, the ProfanityFilter could return a list of profane words it found, and you could do a global search and replace on the original phrase.

    Replace:

    public bool containsProfanity(string checkStr)
    

    with

    public class ProfanityResult
    {
        public bool Profane { get; set; }
        public List<string> ProfanityWords { get; set; }
    }
    
    
    public ProfanityResult containsProfanity(string checkStr)
    

    UPDATE

    Assuming you go with the second option, you would do something like:

    string markedMessage = context.Request["message"];
    if (result.Profane)
    {
        foreach (string word in result.ProfanityWords)
        {
            markedMessage = markedMessage.Replace(
                               word, 
                               "<span class=\""profane\"">" + word + "</span>");
        }    
    }
    

    This approach isn’t terribly efficient as it creates a new copy of the string for each replacement, but if you’re taking about a brief comment or post, you will not notice the inefficiency.

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

Sidebar

Related Questions

I have a form that pop up inside a layer, and I need to
I have a tell a friend pop up email form that allows users to
I have a pop up form that i wish to close on successfull submit
I have created a macro for excel which will pop up form that contains
I have a form that contains a TextBox. A pop up window will return
I have a form that allows users to view some terms and conditions, which
I have a form that calls a success message with this code: // Form
I have some radio buttons on my page that pop up for users to
I currently have form that checks if a user has unsubmitted changes when they
I have a form that I'm submitting through AJAX. The form includes many fields,

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.