I have attached the link to fiddle to simulate the problem I got.
eg: I entered 12345 > point the cursor in the middle 12|345 > type "space" > 123|45
the cursor will go backward after I type the "space".
Question: How can I make it stay at the same place as it is before?
document.querySelector("#removeSpace").onkeyup = function()
{
var start = this.selectionStart,
end = this.selectionEnd;
this.value = this.value.replace(/\s/g,"");
this.setSelectionRange(start, end);
};