JSFiddle - React, Tailwind, and code Playground
HTML
<input id='text_precioDec' />
CSS
.text_dec{
background-color:#cfc;
}
.text_dec_err{
background-color:#fcc;
}
JavaScript
self.onload = function(){
document.getElementById('text_precioDec').onkeyup = function(){
if (filtrar_Num(this, 1, 2)) this.className="text_dec";
else this.className="text_dec_err";
}
};
function filtrar_Num(text, t_min, t_max){
//devuelve verdadero si solo hay digitos del 0-9 sino falso
//y la cantidad de caracteres debe estar entre $min y $max
texto=text.value;
var RegExPattern = new RegExp("^[0-9]{" + t_min + "," + t_max + "}$","i");
return RegExPattern.test(texto);
}