How to insert space every 4 characters for IBAN registering?

前端 未结 9 1711
感情败类
感情败类 2020-11-29 03:28

I\'m really new in JavaScript and I would like to add to my input text, space insertion for IBAN account registering.

9条回答
  •  渐次进展
    2020-11-29 04:08

    This is the shortest version using JQuery on input with type number or tel:

    $('input[type=number], input[type=tel]').on('input', function (e) {
         e.target.value = e.target.value.replace(/[^\dA-Z]/g, '').replace(/(.{4})/g, '$1 ').trim();
    });
    

    You can also change the 4 to any other character limit you want.

提交回复
热议问题