A
A
asd dsa2018-11-27 02:07:05
JavaScript
asd dsa, 2018-11-27 02:07:05

How to do validation for angular-material datepicker?

How to make validation for datepicker so that it would be possible to enter the date in the input only in the format "dd.mm.yy" ?

<mat-form-field appearance="fill" class="field">
                        <mat-label>Date</mat-label>
                        <input matInput [matDatepicker]="picker1" id="expdt" [formControl]="expdate" required>
                        <mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
                        <mat-datepicker #picker1></mat-datepicker>
                        <div class="show-errors"
                             *ngIf="expenseForm.get('expdate').dirty && expenseForm.get('expdate').errors">
                            <mat-error
                                    *ngIf="expenseForm.get('expdate').errors.required">
                                Please enter date
                            </mat-error>
                            <mat-error
                                    *ngIf="expenseForm.get('expdate').errors.pattern">
                                Please enter a valid date
                            </mat-error>
                        </div>
                    </mat-form-field>

expdate = new FormControl('', [Validators.required]);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question