Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NET
When i enter an unused words in an Textbox i should restrict it?How to restrict the Textbox?
 
unused words means bad words mainly used for comments.
i don't want to use string array to filter the Textbox. Give me other examples please.
 
Thanks in advance.
Posted 4-Jan-13 19:12pm

Comments
Sergey Alexandrovich Kryukov - 5-Jan-13 1:30am
What could be a problem here? What did you try? It looks like the solution is contained in the formulation of your requirements? Is it about English words or something else? —SA
sivateja471 - 5-Jan-13 1:56am
for example when you post something in facebook many peoples comments on it.some of them may be vulgar word.that vulgar words should not be entered in the textbox how to restrict it?without entering the words.this is my problem sir. i don't want to use the string array give me other ways sir to validate the textbox. thank you
ridoy - 5-Jan-13 1:43am
Your question is incomplete,but i think regular expression(regex in C#) would be a good one for you to validate your textbox string.
sivateja471 - 5-Jan-13 1:54am
for example when you post something in facebook many peoples comments on it.some of them may be vulgar word.that vulgar words should not be entered in the textbox how to restrict it?without entering the words.this is my problem
Sergey Alexandrovich Kryukov - 5-Jan-13 2:06am
First of all, didn't I already explain everything in my answer? Now, without entering the words?.. I was thinking about it (having some of those vulgar words in mind :-), but finally I did not dare to assume that you can be so unreasonable. Do I understand you right? Do you mean that those words would never appear if a user tries to type them? Or you simply don't want to prepare the data containing all the words you want to restrict? I can clearly proof that this "without entering" makes no sense at all, but do I need to? It sounds too obvious... Well, if you ask me, I will explain, but the answer along will probably longer then Solution 1. So, please reply... —SA
Sergey Alexandrovich Kryukov - 5-Jan-13 2:15am
Who are "we"? This is the key. Are you getting it finally? —SA
Sergey Alexandrovich Kryukov - 5-Jan-13 2:16am
OK, keep reading. Read, understand and think, and only then ask. —SA
Sergey Alexandrovich Kryukov - 5-Jan-13 2:08am
Did you understand my question. In other words, before discussing anything, you need to answer this question: "without entering the words" -- you mean entering by who? —SA
Sergey Alexandrovich Kryukov - 5-Jan-13 2:14am
And also, think of it in this way. This is a Web application. You concern is not allow some words to appear on the Web pages. You can always restrict it. If you think about what a text box is, you can see that, in a way, its content does not belong to you. It exists solely on the client side of each user. The users never see the content until the data is included in HTTP request (with "post" method). From this point, the content being entered simply does not exist for you. And you can filter HTTP request. Is that clear? Well, just think a bit... —SA

2 solutions

Please see my comments. Everything is already in your question. Apparently, to filter out "unused words", you need to know them all and prepare some dictionary of them, in fact, just a list. Convert them all in lower case (for example). And then,
string messageFormat = @"The word ""{0}"" is a bad one. Did you mom teach your to be nice?"
string message;
string content = myTextBox.Text.ToLower();
foreach(unusedWord in unusedWordList)
   if (content.Contains(unusedWord)) {
      message = string.Format(messageFormat, unusedWord);
      break; // I would prefer not to mention all of the offenses...
   }
// use message to make sure the offender can see it and feel ashamed...
 
Please see:
http://msdn.microsoft.com/en-us/library/system.string.aspx[^],
http://msdn.microsoft.com/en-us/library/e78f86at.aspx[^],
http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx[^].
 
Note: during answering this question, no "unused words" were written. Do you need to explain why? Simple: because hard-coding of immediate constants is a great sin for a software developers.
 
To be completely honest, I must confess that some "unused words" came to my mind during reading of the question. I resisted it; please appreciate that. Smile | :)
 
—SA
  Permalink  
Comments
jkirkerx - 5-Jan-13 2:26am
I just wanted to type F*** for the heck of it. See what CJ does with the word. Well, it's a waste of time to control what's typed in the textbox, all you can do is strip out unwanted chars or char arrays after submission
Sergey Alexandrovich Kryukov - 5-Jan-13 2:33am
Of course. And what do you think I'm talking about? Tell this to OP please, do me a great favor; I am out of the ways to explain this simple thing. —SA
I would nothing during composition, when the user types. You cant control what people type, and if you did, you could spend years comparing every word against your dictionary.
 
Just strip out your words after submission, you can start with 1 or 2 words and then expand your bad word dictionary.
 
Sergey's post gives you the information needed to strip words.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 578
1 Ron Beyer 326
2 Tadit Dash 253
3 samadhan_kshirsagar 229
4 OriginalGriff 198
0 Sergey Alexandrovich Kryukov 7,041
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,372
4 CPallini 3,034


Advertise | Privacy | Mobile
Web04 | 2.6.130619.1 | Last Updated 5 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid