关于文本框验证 [英] About textbox validation

查看:77
本文介绍了关于文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在文本框中输入未使用的单词时,我应该限制它吗?如何限制文本框?



未使用的单词表示主要用于评论的不良单词。

i不想使用字符串数组来过滤文本框。请给我其他的例子。



提前致谢。

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.

推荐答案

请参阅我的评论。一切都在你的问题中。显然,要过滤掉未使用的单词,你需要全部了解它们并准备一些它们的字典,实际上只是一个列表。将它们全部转换为小写(例如)。然后,

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...





请参阅:

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 [ ^ ]。



注意:在回答期间这个问题,没有写出未使用过的词。你需要解释原因吗?简单:因为立即常量的硬编码对于软件开发人员来说是一个巨大的罪恶。



说实话,我必须承认在阅读这个问题时,我想起了一些未使用过的词。我抵制了它;请欣赏。 :-)



-SA



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


当用户输入时,我在构图期间什么都不会。你无法控制人们键入的内容,如果你这样做,你可以花费数年时间将每个单词与你的字典进行比较。



提交后删除你的单词,你就可以开始用1或2个单词然后展开你的坏词词典。



谢尔盖的帖子为你提供了删除单词所需的信息。
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.

这篇关于关于文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆