JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="test" value=0 />
<button id="testButton">test</button>
CSS
input.error {
background: red;
}
JavaScript
function checkNumberWithComma(textBox) {
if ((textBox.value == 0 || textBox.value) && textBox.value.match(/^\d{0,3}(?:,\d{3})*$/)) {
$(textBox).removeClass("error");
}
else {
$(textBox).addClass("error");
}
}
function testFunc() {
checkNumberWithComma(document.getElementById("test"));
}
$(document).ready(function() {
document.getElementById("testButton").onclick = testFunc;
});