title: How to validate date in Angular 5 app using datepicker?
body: <p>I have the current template:</p>
  
  <pre><code>&lt;input type="text" class="datepicker" name="my_date" placeholder="mm/dd/yyyy" #myDate="ngModel" [(ngModel)]="myDate" id="my_date"&gt;
  &lt;div class="error_message" *ngIf="myDate.errors?.invalidDate"&gt;
      Please enter valid date
  &lt;/div&gt;
  </code></pre>
  
  <p>I have the following code in onInit:</p>
  
  <pre><code>setTimeout(function () {
        $('.datepicker').datepicker({
          autoclose: true,
          dateFormat: 'MM/dd/yyyy'
        }).on('hide', function(e) {
            $('.datepicker').blur();
        });    
      }, 10);
  </code></pre>
  
  <p>And when saving the company I have the validation logic:</p>
  
  <pre><code>if (validateDate(this.myDate) == false) {     
          myFormDirective.form.controls['my_date'].setErrors({'invalidDate': true});
      }   
  </code></pre>
  
  <p>The problem is that when the date is invalid datepicker put today date instead when
  onblur. To explain the question I'll give 2 scenarios:
  1. 03/10/1800 is not valid date (less than 1900) and when onblur fired, the error is shown correctly.
  2. 01/32/2002 is not valid date but, in this case datepicker instead select another valid date in year 2002 02/01/2002 instead of showing error.</p>
  
  <p>Any idea how tom make sure validation happening on blur ?</p>