jquery-meiomask
jquery-meiomask copied to clipboard
Correct time mask
There is way to have correct time mask? 23:59 Default options is 29:59, that it allows to enter 15:00, but it also doesn't restrict 25:00
I'm also experiencing this issue. There's any patch to fix this?
Hi, I resolved this issue with the combination of mask and regular jquery keypress event. If the first letter entered is '2' then I am changing the mask value to "23:59". My code is $("body").on("keyup", "input[alt='time']", function (event) { if (event.keyCode != 9 && event.keyCode != 16 && (event.keyCode < 37 || event.keyCode > 40)) { var value = $(this).val(); hours= value.split(':')[0]; if (hours.length == 1) { if (parseInt(value) == 2) { $(this).setMask("23:59"); } else { $(this).setMask("29:59"); } } } });
Hi @emaiax I use a similar to @mrapaka "hack", but built-in mask for time will be great and it would not confuse many users.
$("input[alt='time']").setMask().keypress(function ()
{
var currentMask = $(this).data('mask').mask;
var newMask = $(this).val().match(/^2.*/) ? "23:59" : "29:59";
if (newMask != currentMask)
{
$(this).setMask(newMask);
}
});
@disshishkov I've used the same approch. Thanks a lot! :)