2010-03-30 92 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

相关问题