1

how can i set min and max to date in input type date

i try

<input name="DOB" id="DOB" class="enterAddressFormField" placeholder="Date of birthday&nbsp;" size="50" maxlength="60" pattern="yyyy-MM-dd" type="text" onfocus="this.type='date';this.max=='1979-12-31';this.min=='1910-01-01';this.setAttribute('onfocus','');this.blur();this.focus();">

and

<input name="DOB" id="DOB" class="enterAddressFormField" placeholder="Date of birthday&nbsp;" size="50" maxlength="60" pattern="yyyy-MM-dd" min="1910-01-02"  max="1979-12-31" type="text" onfocus="this.type='date';this.setAttribute('onfocus','');this.blur();this.focus();">
IBRA
  • 143
  • 1
  • 2
  • 8
  • Please please do not use inline code like that, the readability is horrible. Use external event handlers. – Sterling Archer Dec 22 '15 at 20:25
  • You're using `type="text"`, and inputs of that type don't understand the `min` and `max` attributes. Inputs of type `"date"` are supposed to, but I don't know of any platform on which they actually do (though I'd love to be wrong). – Pointy Dec 22 '15 at 20:29
  • @SterlingArcher Can you tell me how, please :) – IBRA Dec 22 '15 at 20:31
  • @Pointy i ues type="text" to show the placeholder – IBRA Dec 22 '15 at 20:33
  • If you use `type="text"` the user will have to type in a date. If you use `type="date"` the user will get the native iOS date control. However, as I said, I don't think Safari supports `min` or `max` for date controls. Personally I think the native date control is user-hostile anyway, but for touch screen use you really need something better than typing with the keyboard. – Pointy Dec 22 '15 at 20:48
  • @Pointy - That is correct. `min` and `max` are not supported currently. Check here for the latest support https://caniuse.com/#search=input%20date – Branden Barber Mar 11 '20 at 20:43

1 Answers1

0

You should use datepicker js

$('#datepicker').datepicker({
  dateFormat: "yy-mm-dd",
  maxDate:'+1m +10d',
  minDate: -10
 });

here check it out

https://makitweb.com/set-minimum-maximum-date-jquery-ui-datepicker/

jQuery DatePicker Min Max dates

Ravi Makwana
  • 2,782
  • 1
  • 29
  • 41