Recently, I have started working with Angular and in my application I am facing a challenge regarding date validation. I need to validate a date input and display an error message based on the validation criteria.
To achieve this, I am utilizing ngx-bootstrap datepicker component in my HTML code:
<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>
I have successfully implemented the required field validation, but now I face the next task - validating the date field to accept only numbers in the format "mm/dd/yyyy". In my app.component.ts file, I need assistance in converting the default date format (2018-06-11T18:30:00.000Z) to the desired format.
If anyone has a solution or suggestions on how to accomplish this task, your help would be greatly appreciated.