Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
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

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,
C#
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. :-)

—SA
 
Share this answer
 
v2
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900