Snippets

SOTA Studio Einfache IBAN Formatierung

Created by Andy Hausmann
<label for="iban">iban</label>
<input id="iban" type="text" name="iban" />

<script type="text/javascript">
document.getElementById('iban').addEventListener('input', function (e) {
  var target = e.target, position = target.selectionEnd, length = target.value.length;
  
  target.value = target.value.replace(/[^\dA-Z]/g, '').replace(/(.{4})/g, '$1 ').trim();
  target.selectionEnd = position += ((target.value.charAt(position - 1) === ' ' && target.value.charAt(length - 1) === ' ' && length !== target.value.length) ? 1 : 0);
});
</script>

Comments (1)

  1. Andy Hausmann
    • mit allen IBAN kompatibel
    • erwartet Großbuchstaben
    • Cursorbedienung möglich (vor und zurück) zum löschen, ergänzen
    • Copy-Paste möglich
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.