In my web application I have an input field called \"Budget\" where users enter the proposed budget for a project. I need to create a masked input to automatically bring the
Simple Solution using Only Javascript.
String.prototype.reverse = function () {
return this.split("").reverse().join("");
}
function reformatText(input) {
var x = input.value;
x = x.replace(/,/g, ""); // Strip out all commas
x = x.reverse();
x = x.replace(/.../g, function (e) {
return e + ",";
}); // Insert new commas
x = x.reverse();
x = x.replace(/^,/, ""); // Remove leading comma
input.value = x;
}
.currencyinput {
border-color: #98969a;
border-style: solid;
border-width: 0.5px;
display: inline-block;
}
.currencyinput input {
border-style: solid solid solid none;
border-width: 0 0 0 thin;
}