jquery-meiomask icon indicating copy to clipboard operation
jquery-meiomask copied to clipboard

Correct time mask

Open disshishkov opened this issue 12 years ago • 4 comments

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

disshishkov avatar Jul 31 '13 14:07 disshishkov

I'm also experiencing this issue. There's any patch to fix this?

emaiax avatar Feb 25 '14 00:02 emaiax

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"); } } } });

mrapaka avatar Feb 25 '14 04:02 mrapaka

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 avatar Feb 25 '14 05:02 disshishkov

@disshishkov I've used the same approch. Thanks a lot! :)

emaiax avatar Feb 25 '14 13:02 emaiax