Without a jQuery, you will need to do everything in the hand, which is much more complicated ... But you can use onKeyPress to count the digits while typing:
<input type="text" onkeypress="mascara()">
and the function:
var count = 0;
function mascara(){
count++;
alert(count);
}
and then put a if
to when they reach 4 (or 5) digits add a "-" in front. I think with pure Javascript it looks something like this:
if(count == 5){
var digitos = document.getElementById('inputComMascara').value;
alert(digitos);
document.getElementById('inputComMascara').value = digitos+'-';
}
If it is to do so, I also recommend adding a script to decrement the counter if the person clicks the Backspace
, or better yet, instead of the counter use .lenght()