[英]Password Validation error in Angular Reactive Form Validator
Using Angular Reactive Form to validate password which as to match Password with atleast : 使用Angular Reactive Form验证密码,以使密码与atleast匹配:
|*> 1 lowercase
|*> 1 uppercase
|*> 1 numeric
|*> 8 char longer
"^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})"
<form [formGroup]="NamFomNgs">
<label>Email :
<input type="email" name="MylHtm" formControlName="MylNgs">
</label><br>
<div class="ErrMsgCls" *ngIf="(NamFomNgs.controls['MylNgs'].touched || NamFomNgs.controls['MylNgs'].dirty) &&
!NamFomNgs.controls['MylNgs'].valid">
<span *ngIf="NamFomNgs.controls['MylNgs'].errors.required">This field is required</span>
<span *ngIf="NamFomNgs.controls['MylNgs'].errors.email">Enter valid email</span>
</div><br>
<label>Password :
<input type="text" name="PwdHtm" formControlName="PwdNgs">
</label><br>
<div class="ErrMsgCls" *ngIf="(NamFomNgs.controls['PwdNgs'].touched || NamFomNgs.controls['PwdNgs'].dirty) &&
!NamFomNgs.controls['PwdNgs'].valid">
<span *ngIf="NamFomNgs.controls['PwdNgs'].errors.required">This field is required</span>
<span *ngIf="NamFomNgs.controls['PwdNgs'].errors.pattern">Enter valid password</span>
</div><br>
<button [disabled]="!NamFomNgs.valid">Submit</button>
</form>
NamFomNgs:FormGroup;
constructor(private NavPkjVaj: ActivatedRoute, private HtpCncMgrVaj: HttpClient,private FomNgsPkjVaj: FormBuilder){
this.NamFomNgs = FomNgsPkjVaj.group(
{
MylNgs:[null,Validators.compose([
Validators.required,
Validators.email ])],
PwdNgs:[null,Validators.compose([
Validators.required,
Validators.pattern("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})")])]
});
}
Screen Shot of Output : 输出屏幕截图:
When I try with https://regex101.com/ 当我尝试使用https://regex101.com/时
The same reg exp shows valid for the requirments. 相同的reg exp显示对要求有效。 But its invalid in Angular.
但是它在Angular中无效。 Kindly help me with right way and to resolve this.
请以正确的方式帮助我并解决此问题。
You have to capture something in your regex, you're only using positive look-ahead groups. 您只需要在正则表达式组中捕获正则表达式中的内容即可。 Just change the length part like this :
只需像这样更改长度部分:
"^(?=.*[az])(?=.*[AZ])(?=.*[0-9]).{8,}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.