JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" class="zip-val" />
JavaScript
$(".zip-val").keyup(function(e) {
if(e.keyCode == 8)
{
if($(this).val().length == 6){
var newText = $(this).val().substring(0 , 5);
$(this).val(newText);
}
}
else if($(this).val().length == 6) {
var newText = $(this).val().substring(0 , 5) + '-' + $(this).val().substring(5);
$(this).val(newText);
}
});