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
    • 377
    Comment on it

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

    We have a TextBox as :-

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

    Write the javascript function as :-

    1. <script type="text/javascript">
    2. function GiveSpace(textboxid, spaceafter) {
    3. spaceafter = spaceafter|| 4;
    4. var v = textboxid.value.replace(/[^\dA-Z]/g, ''),
    5. reg = new RegExp(".{" + spaceafter+ "}", "g")
    6. textboxid.value = v.replace(reg, function (a, b, c) {
    7. return a + ' ';
    8. });
    9. }
    10. </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
Reset Password
Fill out the form below and reset your password: