I have tried this code for password pattern validation but it not works, tell me how to validate the pattern
HTML code:-
<form [formGroup]="myForm" (ngSubmit)="submit()" >
<ion-item>
<ion-label primary floating>PASSWORD</ion-label>
<ion-input type="password" id="password" class="form-control" formControlName="password" minlength="4" maxlength="20" required></ion-input>
</ion-item>
<p *ngIf="myForm.controls.password.errors && myForm.controls.password.dirty ">
<small class="up"><strong><i>Password Must Contain(4-20) 1-char! 1-number!</i></strong></small></p>
</form>
ts file:-
export class SinupPage {
myForm: FormGroup
passwordRegex: any = '((?=.*\d)(?=.*[a-zA-Z]).{4,20})' ;
this.myForm = formBuilder.group({
'password' : new FormControl('',Validators.compose([Validators.required,Validators.minLength(4), Validators.maxLength(20),Validators.pattern(this.passwordRegex]))
}
submit(){
let registerNewUserObj ={
password:this.myForm.value.password
}
When I enter data into the field, getting error Password Must Contain(4-20) 1-char! 1-number! which is
tag, but i need to validate the password like thi must contains 1 char 1 number,
Only entering Chars or Only entering number, the error message is displaying