Reputation: 1304
I am using ng-pick-datetime for selecting and displaying dates. I have changed to format of the date to DD/MM/YYYY
using dateTimeAdapter.setLocale('en-IN')
in constructor. If I click the calendar and select the date Its in format of DD/MM/YYYY
but If I manually type 03/28/2019
, it still accepts. I want to restrict other format except DD/MM/YYYY
even on typing. Please help me out.
Code
<input (ngModelChange)="onChangeDate($event)" [(ngModel)]="dob" name="date" [owlDateTimeTrigger]="dt1" [owlDateTime]="dt1" required>
<owl-date-time class="" [pickerType]="'calendar'" [startView]="'multi-years'" #dt1></owl-date-time>
import { DateTimeAdapter } from 'ng-pick-datetime';
constructor(dateTimeAdapter: DateTimeAdapter<any>){dateTimeAdapter.setLocale('en-IN');}
Upvotes: 0
Views: 405
Reputation: 891
There are several ways to validate your input. Here I have provided solution to your problem.
I have added type of input as "text", pattern as you needed "DD/MM/YYYY" and background css to get valid and invalid status of input tag.
<input type="text" pattern="^([0-2][0-9]|(3)[0-1])(\/)(((0)[0-9])|((1)[0-2]))(\/)\d{4}$" (ngModelChange)="onChangeDate($event)" [(ngModel)]="dob" name="date" [owlDateTimeTrigger]="dt1" [owlDateTime]="dt1" required>
Upvotes: 1