I want to make a text box for entering a 16-digit credit card number. Here I took a ready-made regular expression of a card number in the format: 1111 2222 3333 4444. How to make it so that after entering 4 digits, make a space on the fly, then another 4 digits, a space, etc. (\ d {6} [- \ s]? \ d {12}) | (\ d {4} [- \ s]? \ d {4} [- \ s]? \ d {4} [- s]? \ d {4})

<input type="text" id="card" name="card" maxlength="16"> 

    2 answers 2

    If you write in Google input mask, then you will get a bunch of links on your subject.
    For example, here is http://igorescobar.imtqy.com/jQuery-Mask-Plugin/

       function CreditCard(elem){ var m = elem.value.length+1; if (m > 19 || event.keyCode < 48 || event.keyCode > 57) event.returnValue= false; else if (m == 5 || m == 10 || m == 15) elem.value += ' '; } 
       Поле для ввода номера кредитной карты из 16 цифр <br><br> <input type="text" onKeyPress="CreditCard(this)">