JSFiddle - React, Tailwind, and code Playground
HTML
<input id="myId" type="text" value="AZ"></input>
JavaScript
$("#myId").keydown(function(event){
console.log(this.selectionStart);
console.log(event);
if(event.keyCode == 8){
this.selectionStart--;
}
if(this.selectionStart < 2){
this.selectionStart = 2;
console.log(this.selectionStart);
event.preventDefault();
}
});
$("#myId").keyup(function(event){
console.log(this.selectionStart);
if(this.selectionStart < 2){
this.selectionStart = 2;
console.log(this.selectionStart);
event.preventDefault();
}
});