You can create a simple custom validator as below
import {Injectable} from "@angular/core";
import {FormControl} from "@angular/forms";
@Injectable()
export class DateValidator {
constructor() {
}
static date(c: FormControl) {
const dateRegEx = new RegExp(/^\d{1,2}\.\d{1,2}\.\d{4}$/);
return dateRegEx.test(c.value) ? null : {date: true}
}
}
and call it in your form
senddate: new FormControl(new Date(), Validators.compose([Validators.required, DateValidator.date])),
And then simply show the error in your html
<mat-error *ngIf="form.controls.senddate.dirty && form.controls.senddate.errors?.date">
La date d'envoi n'est pas <strong>valide</strong>
</mat-error>
I hope this could help.