JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" class="dec" maxlength= "10" id="dec" /><br>
<span id="output"></span>
JavaScript
$(".dec").focusout(function (event) {
var nondecimalRegex = /^\d{1,6}$/,
inputtxt = event.target.value,
decimalRegex = /^\d{1,6}\.\d{3}$/;
if (inputtxt.length > 0) {
var resultVal;
if (/^\d{1,6}$/.test(inputtxt)) {
resultVal = inputtxt + ".000";
} else if (/^\d{1,6}\.\d{1,3}$/.test(inputtxt)) {
// count of zeros to add to the end of input val
var c = 3 - inputtxt
.split("\.")[1].length;
resultVal = inputtxt
+ (c == 1 ? "0" : (c == 2 ? "00" : ""));
}
dec.value = typeof resultVal == "undefined"
? "" : resultVal;
}
});
/*$(".dec").focusin(function (event) {
output.innerHTML = "awd";
});*/