如何在angular 4中验证日期
我是angular的新手,在我的应用程序中,我需要验证日期并基于验证显示span消息 这里我使用的是ngx引导日期选择器 HTML:如何在angular 4中验证日期,angular,typescript,Angular,Typescript,我是angular的新手,在我的应用程序中,我需要验证日期并基于验证显示span消息 这里我使用的是ngx引导日期选择器 HTML: 有谁能帮我解决这个问题。您想要哪种类型的日期验证?只是价格是有效日期?如果在enter元素设置sort=“date”,浏览器将确保只输入合法的日期 对于所显示的范围验证器和任何货币验证器都相同。您需要能够在输入详细信息上设置type=“wide variety”,并且可能不需要验证器 如果您仍然希望执行自己的验证,那么可以像使用实例一样使用普通表达式 只需显示货币
有谁能帮我解决这个问题。您想要哪种类型的日期验证?只是价格是有效日期?如果在enter元素设置sort=“date”,浏览器将确保只输入合法的日期 对于所显示的范围验证器和任何货币验证器都相同。您需要能够在输入详细信息上设置type=“wide variety”,并且可能不需要验证器 如果您仍然希望执行自己的验证,那么可以像使用实例一样使用普通表达式
只需显示货币和日期的正则表达式。对于日期,类似这样的东西:javascript-regex验证日期布局检查这里(我已经读过了,希望我的帖子与@shahnawazraza不同)
<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>
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"
}