I have 3 input field,when i write in the field, how to add space between every 2 number using the ID of the input, in javascript? Any help please!
<input type="number" class="phone" placeholder="Phone" id="phone" />
<input type="number" class="phone" placeholder="Second Number" id="secondnumber" />
<input type="number" class="phone" placeholder="Fax" id="fax" />
i'm trying this script, but it's not apply for all the input
const input = document.getElementById("phone") || document.getElementById("secondnumber") || document.getElementById("secondnumber");
input.addEventListener("input", () => input.value = formatNumber(input.value.replaceAll(" ", "")));
const formatNumber = (number) => number.split("").reduce((seed, next, index) => {
if (index !== 0 && !(index % 2)) seed += " ";
return seed + next;
}, "");