title: I need to restrict age for below 18 years age from the current date in Php
body: <p>I need to restrict age for below 18 years of age from the current date in Php using javascript or ajax. How can I do this?</p>
  <p>Please check my code I want to calculate the age onblur or onSubmit Please go through the code.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function getAge(dateString) {
    var today = new Date();
    var birthDate = new Date(dateString);
    var age = today.getFullYear() - birthDate.getFullYear();
    var m = today.getMonth() - birthDate.getMonth();
    var da = today.getDate() - birthDate.getDate();
    if (m &lt; 0 || (m === 0 &amp;&amp; today.getDate() &lt; birthDate.getDate())) {
      age--;
    }
    if (m &lt; 0) {
      m += 12;
    }
    if (da &lt; 0) {
      da += 30;
    }
    return age;
  }
  var age = getAge("1987/08/31");
  alert(age);
  if (age &lt; 18) {
    alert("This age is restrict");
  
  } else {
  
    alert("This age is allowed");
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form&gt;
    &lt;input type="text" id="dob" onBlur="function getAge(dateString)" /&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>