title: jquery validate date of birth in multiple text fields
body: <p>I've been searching for a definite way to validate the date of birth when it's split in three different text fields. SO far I have a single input field that handles that correctly, but I can't change the html code.SO I still need this to comply with the 3 text-field group.I read that using an hidden input field that validates the values entered in the three fields for date of birth can be a solution. Can anyone give me hand with this.</p>
  
  <p>This is my jsfiddle: <a href="http://jsfiddle.net/b8fubr5u/1/" rel="nofollow">http://jsfiddle.net/b8fubr5u/1/</a></p>
  
  <pre><code>$(document).ready(function () {
      $.validator.addMethod("dob", function (value, element) {
          var result = true;
          var ageMin = 18;
          var ageMax = 85;
  
          //is the date valid?
          //is it within the allowed range
          var myDate = value.split("/");
          var subDay = myDate[0];
          var subMonth = myDate[1] - 1;
          var subYear = myDate[2];
          var subDate = new Date(subYear, subMonth, subDay);
          // this will "correct" any out of range input
          var calcDay = subDate.getDate();
          var calcMonth = subDate.getMonth();
          var calcYear = subDate.getFullYear();
          // this checks to see if any of the submitted input was out of range
          // comment this out to ignore the discrepancy if you want to set a "corrected" value below
          if (calcDay != subDay || calcMonth != subMonth || calcYear != subYear) {
              $.validator.messages.dob = "Invalid date";
              result = false;
          }
  
          if (result) {
              var currDate = new Date();
              var currYear = currDate.getFullYear();
              var currMonth = currDate.getMonth();
              var currDay = currDate.getDate();
  
              var age = currYear - subYear;
  
              if (subMonth &gt; currMonth) {
                  age = age - 1; // next birthday not yet reached
              } else if (subMonth == currMonth &amp;&amp; currDay &lt; subDay) {
                  age = age - 1;
              }
  
              if (ageMin != undefined) {
                  if (age &lt; ageMin) {
                      $.validator.messages.dob = "Min 18 years old";
                      result = false;
                  }
              }
  
              if (ageMax != undefined) {
                  if (age &gt; ageMax) {
                      $.validator.messages.dob = "Invalid date";
                      result = false;
                  }
              }
          }
          return result;
      },
          "Please enter a date in the format DD/MM/YYYY");
  
      $("#form").validate({
          rules: {
              dateBirth: {
                  required: true,
                  dob: true
              },
              month: {
                  required: true,
                  dob: true
              },
              dobDay: {
                  required: true,
                  range: [1, 31]
              },
              dobMonth: {
                  required: true,
                  range: [1, 12]
              },
              dobYear: {
                  required: true
              }
          }
  
      });
  });
  </code></pre>