最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to restrict user input of 24 format time into input field? - Stack Overflow

programmeradmin5浏览0评论

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 .inputmask

But I dont know how to do what I want. Thx a lot.

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.

Share Improve this question asked Aug 3, 2012 at 22:06 iyeliyel 1351 gold badge4 silver badges10 bronze badges 3
  • What have you tried ? – Jerska Commented Aug 3, 2012 at 22:09
  • Question needs to show more research effort. What is wrong with the plugin you posted? – Ruan Mendes Commented Aug 3, 2012 at 22:11
  • Everything is fine with plugin, but I didn't understand – how to do what I want. – iyel Commented Aug 3, 2012 at 22:13
Add a comment  | 

4 Answers 4

Reset to default 17

Like that ?

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

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/

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

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);
发布评论

评论列表(0)

  1. 暂无评论