JSFiddle - React, Tailwind, and code Playground
by padma rubhan
HTML
<input type="text" id="nohrs" placeholder="hh:mm" maxLength="5"/>
JavaScript
$("#timeFormat").keypress( function(evt) {
if (/^[0-9:.]+$/i.test(String.fromCharCode(evt.charCode)) === false && evt.which != 08 && evt.which !== 0 ) {
evt.returnValue = false;
return false;
}
});
$("#timeFormat").blur(function () {
var value = $(this).val();
var re = /[0-9][0-9]:[0-9][0-9]/;
if (value.match(re)) {
if (value== "00:00") {
$("#timeFormat").val('');
alert('Enter the valid time format as HH:MM');
}
}
else{
$("#timeFormat").val('');
alert('Enter the valid time format as HH:MM');
}
});