我需要设置银行号码的文本输入格式,以便数字看起来像这样:


  11 2490 1111 0000 0000 2222 3333


问题是我只想向用户显示此格式(带空格),但将其发送到没有它的服务器(11249011110000000022223333)。我该如何实现?

编辑

这是我使用formatter.js库(http://firstopinion.github.io/formatter.js/index.html)编写的:

<script>
$(document).ready(function () {
        var formatted = new Formatter(document.getElementById('bank_account-0'), {
        'pattern': '{{99}} {{9999}} {{9999}} {{9999}} {{9999}} {{9999}} {{9999}}',
        'persistent': false
    });
});
</script>

最佳答案

您可能会考虑在每次输入未聚焦或粘贴到以下值时将值更改为:

var a = document.getElementById('yourInputId');
a.onblur = function() { this.value = this.value.replace(/ /g, ''); };


暗示:
您可以考虑减少服务器端的空格。这可能是服务器端验证的一部分。

关于javascript - 格式化银行帐户输入仅用于显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43918495/

10-10 19:25