title: Year validation in Javascript
body: <p>I want to do year validation whre it should be only numeric and Its should be 4 digit long and between 1920 to current year for that I have create Javascript function as follows:</p>
  
  <pre><code>function yearValidation(year) {
      var text = /^[0-9]+$/;
      if (year != 0) {
          if ((year != "") &amp;&amp; (!text.test(year))) {
  
              alert("Please Enter Numeric Values Only");
              return false;
          }
  
          if (year.length != 4) {
              alert("Year is not proper. Please check");
              return false;
          }
          var current_year=new Date().getFullYear();
          if((year &lt; 1920) || (year &gt; current_year))
              {
              alert("Year should be in range 1920 to current year");
              return false;
              }
          return true;
      }
  </code></pre>
  
  <p>and called it on <code>onkeypress="return yearValidation(this.value)"</code></p>
  
  <p>But when I enter <code>1</code> it gives me alert:</p>
  
  <blockquote>
    <p>Year should be in range 1920 to current year</p>
  </blockquote>