Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to give space to a Text input

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 354
    Comment on it

    How to give space after 4 characters to an TextBox input as well as retrict alphabets.

    We have a TextBox as :-

          <asp:TextBox ID="txtCardNumber" class="cardnumber" runat="server" 
                 onkeyup="GiveSpace(this,4)" MaxLength="20" ></asp:TextBox>
    

    Write the javascript function as :-

                <script type="text/javascript">
                        function GiveSpace(textboxid, spaceafter) {
                        spaceafter = spaceafter|| 4;
                     var v = textboxid.value.replace(/[^\dA-Z]/g, ''),
                      reg = new RegExp(".{" + spaceafter+ "}", "g")
                     textboxid.value = v.replace(reg, function (a, b, c) {
                     return a + ' ';
                      });
                     }
                  </script>
    

    This will restrict alphabets as well as give a space after every 4 numbers we enter in a textbox.

    Note:- Very useful on the payment page when we ask for the credit card number.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: