Hello everyone and my problem faced is when user key in Malaysian Identity Card "930402084401", I want the key in number to automatically add - to become "930402-08-4401".
When User key in 930402084401
What I want in my textbox => 930402-08-4401
I try to refer to the code where the code will automatically add space every 4 numbers, but I totally have no idea how to change the code.
document.getElementById('creditSpace').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);
});
<label><input id="creditSpace"> CC Details </label>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…