How could I force the text in the \"username\" text input
to be lower-case regardless of what user types?
setInterval()
will run if the user pastes something in
setInterval(function(){
let myinput = document.getElementById('myinput');
//make lowercase
myinput.value = myinput.value.toString().toLowerCase();
//remove spaces (if you want)
myinput.value = myinput.value.toString().replace(' ', '');
//force specific characters
myinput.value = myinput.value.toString().replace(/[^a-z0-9\/\-_]/, '');
}, 10);
because this is a loop function using .replace()
, replacing only first occurrence at a time, but still looping all of them, this appears to animate removing spaces on pasted text.