Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limiting date range in HTML 5 [duplicate]

I have a input field with type date

<input type="date" id="datepick" name="mybirthday" placeholder="Birthdate(MM/DD/YYYY)" />

Here I want to limit the date range that the user can choose. To be more specific, I dont want the user to choose a birthdate like 22/08/2015. How can I do this?

like image 809
Aravind Bharathy Avatar asked Jun 25 '13 07:06

Aravind Bharathy


People also ask

How do you create a date range in HTML?

The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from. If min and max values are not set then default min value is set to “01-01-1920” and default max value is set to “01-01-2120”.

How do you set a number limit in HTML?

The HTML <input> tag is used to get user input in HTML. To give a limit to the input field, use the min and max attributes, which is to specify a maximum and minimum value for an input field respectively. To limit the number of characters, use the maxlength attribute.

How do I limit the date selection in HTML?

You can add a min or max attribute to the input type=date . The date must be in ISO format (yyyy-mm-dd). This is supported in many mobile browsers and current versions of Chrome, although users can manually enter an invalid date without using the datepicker.


1 Answers

Use the min and max attributes:

<label>Enter a date before 1989-10-30:</label>
<input type="date" name="myDate" max="1989-10-29">

<label>Enter a date after 2001-01-01:</label>
<input type="date" name="myDate" min="2001-01-02">
like image 76
Matt Cain Avatar answered Sep 20 '22 18:09

Matt Cain