title: How to format and validate birth date node js
body: <p>I would like users would be > 18 years. So birth date entered should be > 18 years.</p>
  
  <p>Which is the best way to do it?</p>
  
  <p>I have a component for registration and I have the field like this:</p>
  
  <pre><code>&lt;mat-form-field id="birth-date"&gt;
                &lt;input matInput [matDatepicker]="picker" placeholder="mm/dd/yy" name="birthDate" [(ngModel)]="birthDate"&gt;
                &lt;mat-datepicker-toggle matSuffix [for]="picker"&gt;&lt;/mat-datepicker-toggle&gt;
                &lt;mat-datepicker #picker&gt;&lt;/mat-datepicker&gt;
  &lt;/mat-form-field&gt;
  </code></pre>
  
  <p>In my usersRouter I have the function for registration:</p>
  
  <pre><code>router.post('/users/register', (req, res) =&gt; {
          ...
          const user = new User({
              ...
              birthDate: req.body.birthDate,
              ...
          });
       ...
  });
  </code></pre>
  
  <p>Also, I use mongo and in the UserSchema I have this for the birth date:</p>
  
  <pre><code>birthDate: {
          type: Date,
          required: true
  }
  </code></pre>
  
  <p>Thanks!</p>