JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" name="" id="mascara" maxlength="6" />
JavaScript
function mascara(o,f){
v_obj=o
v_fun=f
setTimeout("execmascara()",1)
}
function execmascara(){
v_obj.value=v_fun(v_obj.value)
}
function mask(v){
v=v.replace(/^(\d{4})(\d)/g,"$1-$2");
v=v.replace(/(\d)(\d{4})$/,"$1$2");
return v;
}
function id( el ){
return document.getElementById( el );
}
window.onload = function(){
id('mascara').onkeyup = function(){
mascara( this, mask );
}
}