Browse Source

正規畫表示驗證

master
HarveyChou 2 years ago
parent
commit
b95b30b8cc
  1. 18
      src/app/app.component.html

18
src/app/app.component.html

@ -1,16 +1,14 @@
<form #form="ngForm"> <form #form="ngForm">
<div> <div>
年齡<input
type="number"
name="age"
#age="ngModel"
[ngModel]="18"
min="18"
密碼<input
type="password"
name="password"
#password="ngModel"
ngModel
pattern="[a-zA-Z]*"
/> />
<ng-container *ngIf="age.touched">
<span *ngIf="age.hasError('min')">
最小年齡為 {{ age.errors?.min.min }} 歲
</span>
<ng-container *ngIf="password.touched">
<span *ngIf="password.hasError('pattern')">密碼只接受英文字母</span>
</ng-container> </ng-container>
</div> </div>
</form> </form>
Loading…
Cancel
Save