JSFiddle - React, Tailwind, and code Playground
HTML
<input id="txtTime"/>
JavaScript
function formatTime(s) {
return s.replace(/\D/g, "").replace(/^(\d\d)(\d\d).*$/, "$1:$2");
}
(function ($) {
$.fn.timeInput = function(){
return $(this).keyup(function(){
$(this).val(formatTime($(this).val()))
});
}
})(jQuery);
$("#txtTime").timeInput()