Validate Date of Birth is not greater than current date using jQuery

This is a common situation where Date of birth needs to validated against the current or today's date. I have to implement the same functionality for my project. I have used jQuery UI datepicker control to select date and textbox was read only, it was pretty easy to implement.

Read my series of articles about jQuery UI datepicker here.

All I needed to do is to stop datepicker control to disable dates greater than today's date. jQuery UI datepicker control provides an option to set the max date. If its value is set to "-1d" then all the dates after current date will be disabled.

Note: I have set the year range statically but this can be set programatically.

$(document).ready(function(){
  $("#txtDate").datepicker(
  { 
  yearRange: 
  '<%=(System.DateTime.Now.Year - 150).ToString()%>:
  <%=System.DateTime.Now.Year.ToString() %>', 
  changeMonth:true, 
  changeYear:true, 
  maxDate: '-1d'
  });
});
See live Demo and Code.

Read my series of articles about jQuery UI datepicker here.

Also read, Validate Date using jQuery

Feel free to contact me for any help related to jQuery. I will gladly help you.



Responsive Menu
Add more content here...