Javascript mask for input hours

Asked

Viewed 2,612 times

3

Someone knows some javascript mask for hours input where the format is not HH:mm. I will use to set the time in project hours and some of them may have more than 24 hours. Example 120:00 hours, 200:00 hours and there goes. The masks I got were only for the 24-hour format.

  • Have you tried Formatter.js ?

  • Can you explain it better? if you have 120:00 how do you want it to appear? what input formats you have and what output formats you want?

  • Hello Sergio. The ideal would be a mask that only allowed the entry of numbers and as they were typed, the time mask was applied. Example: if I type the numbers 2200, the mask would be applied and would be displayed 22:00. If you type 32030, with the mask would be 320:30. I could understand?

2 answers

5

I don’t know if the use of jQuery based plugins is alternative to your project, but there is an excellent plugin for various types of mask: jquery.inputmask.

Then you could do something like:

$('input').inputmask("99:99");

or format the mask the way you need it. This plugin also has many other interesting functionality.

1

Using Regex:

/^([0-9]?[0-9]?[0-9]):[0-5][0-9]$/

This way you can validate the formats:

9:59 | 09:59 | 009:59 | 100:00 | 999:59

Browser other questions tagged

You are not signed in. Login or sign up in order to post.