user1820858
user1820858

Reputation: 55

How to set min value for input type time elements?

How set minimum and maximum values for <input type="time"> elements in HTML5.

I need this because I want to restrict users from inserting non working hours of a day. The minimum value should not be less than 7 AM and maximum value should not be greater than 6 PM.

Upvotes: 3

Views: 13778

Answers (2)

mahdilamb
mahdilamb

Reputation: 535

Javascript is of course a better solution until there's more browser support.

<input type="time" min="07:00:00" max="18:00:00" />

should do the trick

https://www.w3.org/wiki/HTML/Elements/input/time

Upvotes: 5

dsharew
dsharew

Reputation: 10665

I suggest you rather to use javascript.

<script type="text/javascript">
function checktimeval(){
  var timeval=*document.getElementById("theidofurinput").value*;
  if(!(timeval > 1 && timeval < 12)){
    document.getElementById("theidoferrorspan").innerHTML="Please enter time <7 a.m and >6 p.m";
  }
}

Then call this function onblur of the input element.

Upvotes: 2

Related Questions