JSFiddle - React, Tailwind, and code Playground
by Chris Rebert
HTML
<input type="text" maxlength="4" value="1234567" id="q">
JavaScript
var input = document.getElementById('q');
console.log('Before script edit:', input.validity.tooLong);
input.setSelectionRange(input.value.length - 1, input.value.length);
document.execCommand("Delete");
console.log('After script edit:', input.validity.tooLong);