我已经尝试过这段代码,但它无效。
<div>
<span *ngIf="!usernameRef.errors?.required">Amount</span>
<span *ngIf="!usernameRef.errors?.required">Cover amount required.</span>
<span *ngIf="usernameRef.errors?.pattern">Cover amount invalid.</span>
<input type="number" name="Amount" class="form-control" data-field="validate" placeholder="50 000" [(ngModel)]="Amount"
required #usernameRef="ngModel" pattern="[0-9]*" />
</div>
答案 0 :(得分:1)
你的正则表达式也有效,原因有两个: