Reputation: 135
I have an input field with time in HH:MM. And I need to manage that users can only enter correct time, to prevent them from entering wrong time.
A time in 24-Hour Format Regular Expression Pattern is
([01]?[0-9]|2[0-3]):[0-5][0-9]
And I've found mask input plugin https://github.com/RobinHerbots/jquery.inputmask
But I dont know how to do what I want. Thx a lot.
Upvotes: 6
Views: 25391
Reputation: 1
also can use this code
var selector = document.getElementById("aaa");
Inputmask("(09|19|20|21|22|23):(09|19|29|39|49|59)").mask(selector);
Upvotes: -1
Reputation: 11054
Not sure about the plugin you referenced since I don't see a demo page for it. I find that if you need the user to enter times or dates in a certain way, you can't let them key anything. So we use calendar date pickers for dates, and this is the best time picker I've found: http://haineault.com/media/jquery/ui-timepickr/page/
Upvotes: 0
Reputation: 1261
Like that ?
$(document).ready(function(){
$("#time").inputmask("h:s",{ "placeholder": "hh/mm" });
});
Upvotes: 17