【发布时间】:2018-06-29 14:46:15
【问题描述】:
我是 angular 新手,在我的应用程序中,我需要验证日期并根据验证显示跨度消息。
这里我使用的是 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>
在这里我已经完成了所需的字段验证。它工作正常
现在我需要验证日期字段仅接受数字,格式应为“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"
}
谁能帮我解决这个问题。
【问题讨论】:
标签: angular typescript