日期:2014-05-17  浏览次数:20563 次

ASP.NET中textarea禁止输入一些脏话 如:操、操、日.....等如何去做?
ASP.NET中<textarea id="TextArea1" cols="20" rows="2" runat="server">禁止输入一些脏话 如:操、日.....等如何去做?

------解决方案--------------------
汉字博大精深 目测你怎么都限制不完
------解决方案--------------------
C# code
string[] NotWord = new string[4] { "得到的", "的的", "去", "啊" };
                            string[] word = new string[4] { "***", "**", "*", "*" };
                            string txt = txtConfigName.Text.Trim();
                            for (int i = 0; i < NotWord.Length; i++)
                            {
                                if (txt.Contains(NotWord[i]))
                                {
                                    txt = txt.Replace(NotWord[i], word[i]);
                                }
                            }
                            result.ConfigName = txt;

------解决方案--------------------
说实在的,对这种过滤灰常灰常反感。就好比看打码的A片。

这大概也是Z国特色了。
------解决方案--------------------
将这些敏感词存入数据库中。当用户发表评论时判断数据库中是否含有这些敏感词。
 public bool GetForbWord(string msg)
{

List<string>list=dal.GetForbWord();//获取所有的禁用词.
string str= string.Join("|", list.ToArray());
str = str.Replace(@"\", @"\\").Replace(@"{2}", @".{0,2}");
return Regex.IsMatch(msg, str);
}