Add a JQuery Validate rule for No Date Greater Than Today

Author: Steven Neiland

I'm taking a break this week so I'm just going to share this snippet from my archives for adding a JQuery Validate rule which disallows any date greater than today.

function(value, element) {
      var currentDate = new Date();
      var selectedDate = new Date(value);
      return (currentDate >= selectedDate);
"You cannot select a date greater than today."

What Do You Think?

Reader Comments

Comment Etiquette:

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain or appear to be advertisments, will not be published.
  • Comments that appear to be created for the purpose of linkbuilding to commercial sites will be removed.

Archives Blog Listing