【发布时间】:2019-11-15 18:22:27
【问题描述】:
我的密码验证有问题,我正在使用正则表达式,例如:
'(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])'
我的 ng-form 字段是;
password: ['', [Validators.pattern('(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])'), Validators.required]]
在 HTML 中,我的输入为;
<div class="form-group">
<label for="password">Password</label>
<input type="password" formControlName="password" placeholder="******" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.password.errors }" />
<div *ngIf="submitted && f.password.errors" class="invalid-feedback">
<div *ngIf="f.password.errors">Invalid Password</div>
</div>
</div>
其中 f 是函数,例如;
get f() {
return this.userForm.controls;
}
当我输入密码为:Harun123 时,出现密码无效错误。为什么会这样?
【问题讨论】:
-
我还在表达式开头加了^
标签: html regex angular passwords