我尝试了以下方法:
<div class="form-group row">
<label class="col-md-2 col-form-label" for="passcode">Password *</label>
<div class="col-md-3">
<input class="form-control" type="password" placeholder="Password" formControlName="passCode" [(ngModel)]="userDetails.passCode" pattern="^(?=.*\d)(?=.*[a-z])(?!.*\s).{7,12}$">
<div *ngIf="userAdd.controls['passCode'].hasError('required')&&(userAdd.controls.passCode?.dirty ||userAdd.controls.passCode?.touched)" class="alert alert-danger">
{{errorMessageForRequired}}
</div>
<div *ngIf="userAdd.controls['passCode'].errors && userAdd.controls['passCode'].errors.pattern" class="alert alert-danger">
Passcode must contain only letters, numbers and underscores (7-12 characters)
</div>
</div>
</div>
请帮助我
答案 0 :(得分:1)
我认为您的regex有点问题。
符合以下条件的通行证:Qwert!1
。
<form>
<input type="text" pattern="((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\W]).{7,64})" required placeholder="Qwert!1"/>
<input type="submit" />
</form>