JSFiddle - React, Tailwind, and code Playground
HTML
<input id="income" type="text" value="£"/>
JavaScript
$("#income").keydown(function(e) {
var oldvalue=$(this).val();
var field=this;
setTimeout(function () {
if(field.value.indexOf('£') !== 0) {
$(field).val(oldvalue);
}
}, 1);
});
// Add comma to input field
$('#income').keyup(function(event) {
// skip for arrow keys
if(event.which >= 37 && event.which <= 40) return;
// format number
$(this).val(function(index, value) {
return value
.replace(/\D/g, "")
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")
;
});
});