I am designing a time (HH:MM) field using input type text. How to restrict entering a colon manually in input field and auto populate it after 2nd digit? Though I am able to auto populate colon at 3rd place, how to restrict it adding manually at other places. `
const colReg = /([0-9]{2}(?!:))/g;
if (event.target.value.length < 3) {
event.target.value = event.target.value.replace(colReg, "$1:");
}
if (event.target.value.length === 5 && event.target.value.charAt(4) === ':') {
event.target.value.replace(0);
}