How to limit user input of 24-format time in the input field?

I have an input field with time in HH: MM. And I need to control that users can enter the correct time to prevent their wrong time.

Time in a 24-hour format regular expression pattern

([01]?[0-9]|2[0-3]):[0-5][0-9] 

And I found the mask input plugin https://github.com/RobinHerbots/jquery.inputmask

But I do not know how to do what I want. thanks a lot.

+6
source share
4 answers

How which ?

 $(document).ready(function(){ $("#time").inputmask("h:s",{ "placeholder": "hh/mm" }); });​ 
+17
source

I’m not sure about the plugin you linked to, because I don’t see a demo page on it. I find that if you need the user to enter time or dates in a certain way, you cannot let them change anything. So we use calendar date pickers for dates, and this is the best time pick I've found: http://haineault.com/media/jquery/ui-timepickr/page/

0
source
 $(selector).inputmask("h:s",{ autoUnmask:true }); 
0
source

can also use this code

 var selector = document.getElementById("aaa"); Inputmask("(09|19|20|21|22|23):(09|19|29|39|49|59)").mask(selector); 
0
source

Source: https://habr.com/ru/post/922092/


All Articles