Is it possible to add validations/restrictions to date element using HTML api,without jquery?
I am currently using jquery datePicker to display calendar,and for adding restrictions using the beforeShow method of the datePicker.
Now i am trying to use the HTML5 calender and want to know how to add restrictions(eg:disable weendends/holidays) to the HTML5 calendar. Can somebody point me in right direction?
The max attribute specifies the maximum value (date) for a date field. Tip: Use the max attribute together with the min attribute to create a range of legal values.
You can restrict the users from selecting a date within the particular range by specifying MinDate and MaxDate properties. The default value of MinDate property is 1/1/1920 and MaxDate property is 12/31/2120 . Dates that appears outside the minimum and maximum date range will be disabled (blackout).
The <input type="date"> defines a date picker. The resulting value includes the year, month, and day.
Simple JavaScript Function to to check if date is valid. function isValidDate(s) { var bits = s. split('/'); var d = new Date(bits[2] + '/' + bits[1] + '/' + bits[0]); return !!(
You can use min
and max
attributes on your date input.
Spec : http://www.w3.org/TR/html-markup/input.date.html
Edit :
Afaik, there is no way to disable specific days using HTML5 date input...
If you want to be cross-browser, use Modernizr and provide a fallback for old browsers (for example jQuery datePicker) : http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-cross-browser-html5-forms/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With