title: Set a maximum year in datepicker jquery
body: <p>I have the following code </p>
  
  <pre><code>&lt;script&gt;
          $(document).ready(function() {
              $(".datepicker").datepicker( {
          year = today.getFullYear,
          format: " yyyy", // Notice the Extra space at the beginning
          viewMode: "years", 
          minViewMode: "years",
          yearRange: '1920 : year',
          autoclose: true,            
          });
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>as you can see I only need the year, but I don't want to pick the following years... I mean 2020, 2021, 2022... Shouldn't be even able to be picked.. I looked around but couldn't find a solution, can someone help me with that? Thanks</p>
  
  <p>EDIT: </p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function() {
    $('#datepicker').keyup(function() {
  
      var inputVal = $(this).val();
      var dateReg = /^\d{4}$/;
  
      if (dateReg.test(inputVal)) {
        $("#datemsg").html("Valid").css("color", "green");
      } else {
  
        $("#datemsg").html("Invalid date").css("color", "red");
      }
    });
  
    $("#datepicker").datepicker({
      format: " yyyy", // Notice the Extra space at the beginning
      viewMode: "years",
      minViewMode: "years",
      autoclose: true,
      endDate: new Date(),
    });
  });
  &lt;/script&gt;
  </code></pre>