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