溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

敏感詞處理

發(fā)布時(shí)間:2020-08-04 09:27:08 來(lái)源:網(wǎng)絡(luò) 閱讀:685 作者:小仙女KOMons 欄目:開發(fā)技術(shù)

1.js 由于 敏感詞多 倒是頁(yè)面運(yùn)行緩慢 所以最后還是放到c#后臺(tái)實(shí)現(xiàn)過(guò)濾

var words=['敏感詞1','敏感詞2'];
var p='我是敏感詞1,我也是敏感詞2,測(cè)試看看';
for(var i=0;i<words.length;i++){
    p=p.replace(new RegExp(words[i],'ig'),new Array(words[i].length).join('*'));
};
alert(p);

C#形式敏感詞過(guò)濾

 public bool  Read(string txt)

    {

            string path = HttpContext.Current.Server.MapPath("~/Filter/Filter.txt");

            Encoding code = Encoding.GetEncoding("gb2312");

            StreamReader sr = new StreamReader(path, code);

            string temp = Regex.Replace(txt, @"[^\u4E00-\u9FA5]", " ");

            string tmepvalue = sr.ReadToEnd();

            sr.Close();

            bool change = false;

            foreach (string s in tmepvalue.Split('|'))

            {

                string ci = s;

 

                if (txt.Contains(ci))

                {

                    temp = Regex.Replace(txt, ci, "**");

                    change = true;

                }

            }

            if (change)

            {

                string errortxt = "  <script>  $('.success').hide(); $('.warning').show(); $('.intotit').html('警告'); " +

             " $('.errorinfo').html('留言存在非法內(nèi)容,請(qǐng)將**號(hào)位置重新修改。'); $('.showok').show();$('#messages').val('" + temp + "');</script>";

                Page.ClientScript.RegisterStartupScript(this.GetType(), "AA", errortxt);

                return false;

            }

            return true;

 

    }

//Page.ClientScript.RegisterStartupScript這種彈出 會(huì)讓我的html輸入框內(nèi)容為空  只能 彈出后重新賦值一遍

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI