Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add validation/restrictions for HTML5 date field without jquery/javascript

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?

like image 624
kvc Avatar asked Dec 20 '11 11:12

kvc


People also ask

How do I limit a date in HTML?

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.

How do I restrict date in date picker?

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).

How do I make a date picker in HTML?

The <input type="date"> defines a date picker. The resulting value includes the year, month, and day.

Is valid date in jquery?

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 !!(


1 Answers

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/

like image 168
Romain Meresse Avatar answered Sep 25 '22 00:09

Romain Meresse