I ma new to angular ,In my application I need to validate a date and display span message based on validation .
Here I am using ngx-bootstrap datepicker .
HTML:
<label for="mDOB" class="control-label">Date of birth</label>
<input [bsConfig]="bsConfig" type="text" maxlength="10" name="mDOB" [(ngModel)]="mUser.mDOB" #mDOB="ngModel"
placeholder="Date of birth" class="form-control" bsDatepicker required>
<div class="help-block alert-danger col-sm-12" *ngIf="mDOB.errors?.required && mDOB.touched">
* Date of Birth is required
</div>
Here I have done the reguired field validation .it's working fine
Now I need to validate the date field accepts only numbers and format should be "mm/dd/yyyy".
app.component.ts
submitForm(newUser: User): void {
// pattern="^(0?[1-9]|1[0-2])/(0?[1-9]|1[0-9]|2[0-9]|3[01])/\d{4}$";
// newUser.mDOB using this I can get the selected date .
// it always returns 2018-06-11T18:30:00.000Z in this format
// So here I need to convert from this format to "mm/dd/yyyy"
}
Can anyone help me to solve this .