Without a jQuery, you will need to do everything in hand, which is much more complicated... But you can use onKeyPress to count the digits during typing:
<input type="text" onkeypress="mascara()">
and the function:
var count = 0;
function mascara(){
count++;
alert(count);
}
and then put a if for when they reach 4 (or 5) digits add a "-" in front. I think with pure Javascript is more or less like this:
if(count == 5){
var digitos = document.getElementById('inputComMascara').value;
alert(digitos);
document.getElementById('inputComMascara').value = digitos+'-';
}
If you want to do so, I also recommend adding a script to decrease the counter if you click on Backspace, or better yet, instead of the counter use the .lenght()
So why the tags you don’t want are in the question?
– user60252
@Leocaracciolo was made the edition, I had rejected precisely because to read understood that it has nothing with jQuery, ended up in the end AP approved the edition.
– NoobSaibot
@wmsouza, correct, but the question continues with
O site então não possui jQuery, entao não quero ter que adicionar o jQuery e um plugin de máscara para isso.– user60252
Yes, the correct thing is to reverse this issue.
– NoobSaibot
was edited. Thanks for the correction :D
– Dallington Augusto