Add a JQuery Validate rule for No Date Greater Than Today

Author: Steven Neiland
Published:

Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

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.

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

Reader Comments

  • 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 advertisments or appear to be created for the purpose of link building, will not be published.

Archives Blog Listing