0

I'm trying to validate date. It does validate in most cases, but when I enter type number like 15042019, it does not show any error.

The problem is that custom validator I only gets null value or Date instance, so I don't have a chance to do some reqex matching:

<mat-form-field>
  <input formControlName="ratingDate" matInput [matDatepicker]="picker1" 
       placeholder="Rating Date">
  <mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
  <mat-datepicker #picker1></mat-datepicker>
</mat-form-field>


this.formBuilder.group({
  ratingDate: ['', CustomValidators.date],
});

How do I validate date inputs, in Reactive Forms, when using mat-datepicker?

3
  • 1
    Possible duplicate Commented Apr 15, 2019 at 8:22
  • @Liero refrer this example of date validation : stackblitz.com/angular/… Commented Apr 17, 2019 at 7:23
  • @Liero this is not working im getting an error in my html page Property 'date' comes from an index signature, so it must be accessed with ['date'] Commented Jun 29, 2022 at 8:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.