I am currently working with Ionic 4 and Angular 8, attempting to insert a space every 4 digits entered by the user. However, the function I have written seems to be malfunctioning, as it inserts a space after each action the user takes following 4 numbers.
Here is the function I am using:
maskInput(input){
let masked:
Array<String> = input.replace(" ", "").split("");
let res = "";
for(let i = 0; i< masked.length; i++) {
if(i % 4) res += masked[i]
else res += " " + masked[i]
}
return res
}
Is there an issue in my implementation of (ngModelChange) within ion-input? Could the problem lie within the for loop?
To address the spaces problem, I made the following code adjustment:
Array<String> = input.replace(" ", "").split(" ").join("").split("");
However, it still appears to count spaces as input.