2010-03-30 87 views
1

我有一個asp:TextBox,我想驗證用戶輸入的字符數不超過250個字符。如何驗證多行asp:TextBox中允許的最大字符數?

因爲它是一個多行TextBox的MaxLength屬性不起作用。目前,我只看到使用的CustomValidator與服務器端,也許在另外一些JavaScript客戶端驗證檢查TextBox1.Text.Length的選項。

但是是不是有一個簡單的方法來做到這一點,使用標準的ASP.NET驗證程序(的RegularExpressionValidator,RangeValidator控件,CompareValidator,等等)?

在此先感謝!

回答

6

你必須使用的RegularExpressionValidator這一點。此示例允許在多行文本框中最多包含1000個字符:

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" 
      runat="server" Display="dynamic" 
      ControlToValidate="Comments" 
      ValidationExpression="^([\S\s]{0,1000})$" 
      ErrorMessage="Please enter maxium 1000 characters for Comments"> 
    </asp:RegularExpressionValidator> 
+0

它很簡單,它的工作原理!完善!非常感謝你! – Slauma 2010-03-30 11:46:11

相關問題