2012-03-03 61 views
0

有誰知道一個正則表達式驗證器或網站多數民衆贊成停在文本框使用腳本和HTML標記和文字區域正則表達式驗證腳本的HTML文本塊

更新時間:

public static string RegexReplace(string strin, string strExp, string strReplace) 
    { 
     return Regex.Replace(strin, strExp, strReplace); 
    } 

    public static string RemoveHTML(string strText) 
    { 
     return RegexReplace(strText, "<[^>]*>", string.Empty); 
    } 

回答

1

你不會阻止用戶在輸入中輸入數據。你「可以」使用JavaScript,但用戶「可以」禁用JavaScript並做他們想做的事情。

您需要在服務器端進行消毒用戶提交數據後。

檢查出微軟AntiXSS Library,甚至MarkDownSharp可以做到這一點(即使你沒有實際使用Markdown)。或者總是有HtmlAgilityPack爲你解析HTML。

HtmlAgilityPack

PM>安裝,包裝HtmlAgilityPack

MarkDownSharp

PM>安裝,包裝MarkdownSharp

AntiXss

PM>安裝,包AntiXSS

不要,我再說一遍請勿parse html with regular expressions !!!!

+0

您的意思是在驗證器上使用OnServerValidate事件 – ONYX 2012-03-03 04:22:22

+0

不,我的意思是您需要去除易失性腳本...清理輸入...抱歉,我要刪除「驗證」部分。 – 2012-03-03 04:24:21

+0

我已更新我的帖子。像上面的東西會有用嗎?它不會說腳本,但可以用html代替腳本你覺得怎麼樣 – ONYX 2012-03-03 04:30:35