javascriptjqueryjquery-mask

How to use jQuery Mask Plugin to create a customized time mask?


I have a time field where the users can insert the overtime of an employee. In this field they can insert any amount of hour, but the minutes must be between 00 and 59. How could I use the jQuery Mask to make this kind of mask?


Solution

  • I figured out that the translation option can be used to apply some customized rules on the mask. So, I used a regular expression that allow only numbers between 0 and 5 on the tens of minutes.

    var time_options = {
        translation: {
            'M': {pattern: /[0-5]/}, 
        }
    };
    $('.time').mask('00:M0', time_options);