You must Sign In to post a response.
  • Category: ASP.NET

    Regular Expression for Textbox (whose mode is multiple) to allow 100 character

    In my form I used textbox whose mode is multiple.I want to allow only 100 character (including number,special character and char).Maxlength will not work with textbox.What will be my Regular Expression?

    <asp:TextBox ID="tb" runat="server" TextMode="MultiLine" ></asp:TextBox>

    //Regular Expression validator
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
    runat="server" ControlToValidate="tb"
    ErrorMessage="Please enter maximum 100 charachters."
    SetFocusOnError="true" ValidationExpression="^[a-zA-Z.]{0,100}$">
    This include character only.I want number,spl char or any but count should not greater than 100.How to do that?
  • #763980

    Can you try this code for textarea string length

    var maxLength=1000;
    var text = $(this).val();
    var textLength = text.length;
    if (textLength > maxLength) {
    alert("Sorry, you only " + maxLength + " characters are allowed");

    Name : Dotnet Developer-2015
    Email Id

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #763982
    You can do it by adding the simple attribute "maxLength".

    <script type="text/javascript">
    $(document).ready(function() {
    $('#<%=tb.ClientID %>').attr('maxLength', 10);

    Do not set the MaxLength directly to the server side control. Try to do it using Javascript/JQuery

    By Nathan
    Direction is important than speed

  • #764045
    Hai Pinky,
    You can mention all the characters which you want as below:


    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #764247
    Hi pinky,


    RegularExpressionValidator1.ValidationExpression = @"^[0-9A-Za-z!@\.;:'?-]{1,100}$";

    This allows 101 characters if the last character is a newline. As newlines aren't even suppose to be allowed. Use \z instead of $
    RegularExpressionValidator1.ValidationExpression = @"/^[0-9A-Za-z!@.,;:'?-]{1,100}\z/";

    Hope this will help you.

    Shashikant Gurav

Sign In to post your comments