Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input type date min and max values validate against yyyy-mm-dd instead of dd-mm-yyyy

I am using the date input type in HTML5. It is displaying the correctly in the format dd-MM-yyyy. However the min and max values does not validate correctly, because it validates against the format yyyy-MM-dd. I have not been able to change the format the min and max values validates, any ideas?

<input type="date" name="DateName" id="DateID" min="2000-01-01" max="2100-12-31"/>
like image 742
Casper Thule Hansen Avatar asked Jul 03 '13 08:07

Casper Thule Hansen


1 Answers

The attributes value, min and max have the same format for dates. They follow the RFC 3339 where the full data syntax is as:

full-date       = date-fullyear "-" date-month "-" date-mday
date-fullyear   = 4DIGIT
date-month      = 2DIGIT  (01-12)
date-mday       = 2DIGIT  (01-28, 01-29, 01-30, 01-31)

So even if the browser displays you the date in format dd-mm-yyyy internally it's using this syntax.

Anyway, this HTML5 input type is only supported in Safari, Chrome and Opera.

You can try this Fiddle with invalid dates as 12/12/2014, when you submit the form an error message is displayed.

like image 148
Jonathan Naguin Avatar answered Oct 04 '22 18:10

Jonathan Naguin