We all worked on datepicker controls, right? But in some situations we may need to add some validations like to restrict some dates in the picker so that user cannot select those and move further. Here we are going to disable all the coming Saturdays. I hope you will like this.
Using the code
The first thing you need to do is including the needed files:
Once you are done adding the files, you need to add a text box in which we are going to implement the picker.
- <input type="text" value="Select Date Here" />
Now we will create an array which contains the list of dates we need to disable.
- var disabledDates = ["2015-11-28", "2015-11-14", "2015-11-21"]
Next we will load the datepicker to our text box.
- $('input').datepicker(
- {
- beforeShowDay: function(date)
- {
- var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
- return [disabledDates.indexOf(string) == -1]
- }
- });
That’s all we have done it.
Please see the jsfiddle here: Disable Date In DatePicker
Output
Conclusion
Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.
Your turn. What do you think?
A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, ASP.NET Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.
Please see this article in my blog here.



Arul RPosted Jan 17, 2016, 6:03 AM EST
Thanks for nice article
Sibeesh VenuTOP 100Posted Nov 17, 2015, 6:57 PM EST
Raja T Thank you
Sibeesh VenuTOP 100Posted Nov 17, 2015, 6:57 PM EST
Ajay Gandhi Thank you
Sibeesh VenuTOP 100Posted Nov 17, 2015, 6:57 PM EST
Shridhar Sharma Thank you
Sibeesh VenuTOP 100Posted Nov 17, 2015, 6:57 PM EST
Osvaldo Lopez For that I suggest you to use any server side controls. That would be much better. Thanks
Sibeesh VenuTOP 100Posted Nov 17, 2015, 6:56 PM EST
Anu Vivin Thank you
Raja TPosted Nov 17, 2015, 6:02 PM EST
Nice,Thanks for sharing
Ajay GandhiPosted Nov 17, 2015, 8:57 AM EST
Very helpful ...keep it up
Shridhar SharmaPosted Nov 17, 2015, 8:06 AM EST
nice share
Waldo L.Posted Nov 17, 2015, 3:43 AM EST
How do you do in c# ?
Santhakumar MunuswamyPosted Nov 17, 2015, 3:30 AM EST
Good one
Anu VPosted Nov 17, 2015, 1:31 AM EST
good
Sibeesh VenuTOP 100Posted Nov 16, 2015, 10:53 PM EST
Rajeesh Menoth Thank you
Sibeesh VenuTOP 100Posted Nov 16, 2015, 10:53 PM EST
Harshad Pansuriya Thank you
Rajeesh MenothPosted Nov 16, 2015, 10:51 PM EST
Nice One
Harshad PansuriyaPosted Nov 16, 2015, 10:27 PM EST
Nice one