本文介绍了如何设置文本框应该使用验证控件接受(最少50个单词)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文本框,用户必须输入说明。在该文本框中,用户输入的文本不应少于50个字符。如果小于显示错误描述不应少于50个字符。在文本框中,用户可以在文本框中输入最大值beacuse im set column property max in database.so将没有限制。

i have text box in that user has to enter description. In that text box user enter text should not be less than 50 character.if it is less than it show error that "Description shouldn''t be less than 50 characters". In text box user can enter max value in text box beacuse i m set column property max in database.so there will be no limit.

推荐答案

<asp:textbox id="TextBox2" runat="server" xmlns:asp="#unknown">
<asp:regularexpressionvalidator display="Dynamic" controltovalidate="TextBox2" id="RegularExpressionValidator2" validationexpression="^[\s\S]{50,}



using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace skmExtendedValidators
{
   [ToolboxData("<{0}:TextBoxLengthValidator runat=server
         ErrorMessage=\"TextBoxLengthValidator\"></{0}:TextBoxLengthValidator>")]
   public class TextBoxLengthValidator : BaseCompareValidator
   {

      // Properties
      [Bindable(true),
       Description("TextBoxLengthValidator_MaximumLength"),
       Category("Behavior"),
       DefaultValue(-1)]
      public int MaximumLength
      {
         get
         {
            object MaxLengthVS = this.ViewState["MaximumLength"];
            if (MaxLengthVS != null)
            {
               return (int) MaxLengthVS;
            }
            return -1;
         }
         set
         {
            this.ViewState["MaximumLength"] = value;
         }
      }

      protected override bool EvaluateIsValid()
      {
         if (this.MaximumLength < 0)
            return true;

         string ControlToValidateName =
             base.GetControlValidationValue(base.ControlToValidate);

         return ControlToValidateName.Length <=
                   System.Convert.ToInt32(this.MaximumLength);
      }

      ...
   }
}


这篇关于如何设置文本框应该使用验证控件接受(最少50个单词)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:19