js实现卡号每四位空格分隔

Posted Flying bird

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js实现卡号每四位空格分隔相关的知识,希望对你有一定的参考价值。

window.onload =function() {
        document.getElementById("input_num").oninput =function() {
            this.value =this.value.replace(/\s/g,‘‘).replace(/\D/g,‘‘).replace(/(\d{4})(?=\d)/g,"$1 ");;
        };
    };

 

以上是关于js实现卡号每四位空格分隔的主要内容,如果未能解决你的问题,请参考以下文章