title: Validate if age is over 18 years old with Angular Reactive Forms
body: <p>Is there a way to check if a user is over 18 years of age  when they have entered their date of birth using Angular Validators?</p>
  
  <p>My form looks like this:</p>
  
  <pre><code>&lt;form [formGroup]="authForm" (ngSubmit)="submitForm()"&gt;
      &lt;label&gt;Date of birth&lt;/label&gt;
      &lt;input formControlName="day" maxlength="2" placeholder="DD" type="text" /&gt;
      &lt;input formControlName="month" maxlength="2" placeholder="MM" type="text" /&gt;
      &lt;input formControlName="year" maxlength="4" placeholder="YYYY" type="text" /&gt;
      &lt;button [disabled]="!authForm.valid" type="submit"&gt; Check age &lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And then I have these validators set in the TS file:</p>
  
  <pre><code>if (this.authType === 'register') {
      this.authForm.addControl('year', new FormControl('', [Validators.required, Validators.maxLength(4), Validators.minLength(4)]));
      this.authForm.addControl('month', new FormControl('', [Validators.required, Validators.maxLength(2)]));
      this.authForm.addControl('day', new FormControl('', [Validators.required, Validators.maxLength(2)]));
   }
  </code></pre>
  
  <p>So if the conditions above are satisfied in the Validators, the button becomes enabled. But I also need to check that the entered date is over 18 years old before enabling it. This seems tricky as the date is entered via 3 inputs (dd, mm, yyyy). And in this case, I can't use the input date tag. Any suggestions or comments appreciated. Thanks!</p>
  
  <p><strong>P.S. Thanks for all the suggestions about using MomentJS. I'm already using it elsewhere in the app so I'll also use it here.</strong></p>