Jquery calendar Startdate and enddate validation

Yesterday i got some problem , i had 2 text box Start date and end date and i used Jquery calendar to get the date. well now my problem is
1) user should not select date greater than today
2) end date should not less then start date
3) start date should not greater than end date.

I was breaking my head for that at last i found the solution . Here is the code

var date = new Date();
var dates = $("#txtFrom, #txtTo").datepicker({
dateFormat: "mm/dd/yy",
firstDay: 1,
showWeek: true,
maxDate: new Date(date.getFullYear(), date.getMonth(), date.getDate()),
onSelect: function (selectedDate) {
var option = this.id == "txtFrom" ? "minDate" : "maxDate",
instance = $(this).data("datepicker");
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);

In the txtfrom , txtto is the textbox id.

Hope this will help you guys, If any help needed on this Just comment .