I am trying to validate dates using the material date picker. Specifically what I am trying to validate is when the user types \'abc\' into a date field I would like to show th
You can attach a handler on 'dateChange' which is triggered onChange of the input field of the mat-datepicker and validate the user input.
You can also try out 'dateInput' of mat-datepicker.
Refer https://material.angular.io/components/datepicker/api#MatDatepickerInput
Update
HTML
TS
import {Component} from '@angular/core';
import {MatDatepickerInputEvent} from '@angular/material/datepicker';
/** @title Datepicker input and change events */
@Component({
selector: 'datepicker-events-example',
templateUrl: 'datepicker-events-example.html',
styleUrls: ['datepicker-events-example.css'],
})
export class DatepickerEventsExample {
events: string[] = [];
addEvent(type: string, event: MatDatepickerInputEvent) {
this.events.push(`${type}: ${event.value}`);
}
keyEvent(type: string, event: KeyboardEvent) {
this.events.push(`${type}: ${event.target.value}`);
}
}