skip to Main Content

Issue : how to restrict textbox to only allow 10 digits using type = number and hide the arrow on a aspx file
Requirements:

  • no more than 10 digits in the box
  • allows copy and paste but filters out letters in it for eg 1234a or a1234
  • allows only numbers
    <asp:TextBox ID="txt" runat="server" IsReadOnly="false" Type="Number" Maxlength="10" ></asp:TextBox>
    <asp:RegularExpressionValidator ID="RegularExpression1" runat="server" ControValidator="txt" ValidationExpression="d+" ErrorMessage="only numeric values allowed."></asp:RegularExpressionValidator>

2

Answers


  1. Chosen as BEST ANSWER

    This is worked as well

    <asp TextBox ID="txtId" width = "205px" runat="server" MaxLength="10"/>
    <asp:RangeValidator runat="server" ID = "valRangeTxtcontactId" controlToValidate="txtId" Type ="Integer" Minimumvalue = "0" Maximumvalue ="2147483647" CssClass="input-error" ErrorMessage="Integers only" Display="Dynamic"></asp:RangeValidator>


  2. This works:

            <asp:TextBox ID="TextBox1" runat="server"  
                TextMode="Number" Width="187px"
                onkeypress="return this.value.length<=10" >
            </asp:TextBox>
    

    If you need to hide the up/down (spinner), then use this:

    <style>
    
      .myspinhide 
      /* Chrome, Safari, Edge, Opera */
      input::-webkit-outer-spin-button,
      input::-webkit-inner-spin-button 
      {-webkit-appearance: none; margin: 0;}
    
       /* Firefox */
       .myspinhide input[type=number] {-moz-appearance: textfield;} 
    </style>
    
            <asp:TextBox ID="TextBox1" runat="server"  CssClass="myspinhide"
                TextMode="Number" Width="236px"
                onkeypress="return this.value.length<=10"  >
            </asp:TextBox>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search