Friday, June 6, 2014

HTML5 input date validation

HTML5 has <input type="date"> and browsers which support it show their own date picker calender.
And what if you input invalid date, e.g. 2016/2/30?
W3C HTML5 spec says
The value sanitization algorithm is as follows: If the value of the element is not a valid date string, then set it to the empty string instead.
So you never get an original invalid date value.

How can you handle it?


You only know if a value is invalid or not with...


  1. input.validity.badInput
  2. input.validity.valid
  3. input.validationMessage

Further details, please see this: http://stackoverflow.com/questions/13278016/get-input-value-from-html5-inputtype-date-in-chrome/24081375#24081375


No comments:

Post a Comment