I need to validate the strength of a password input form field. The requirements are:
- at least one lowercase char
- at least one uppercase char
- at least one number
(no matter the order)
What I have searched and tried so far goes below, the results are inconsistent.
It seems to validate the order of the regex validation.
What I need is to just check if at least one of the char "types" are present.
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'signup',
templateUrl: './signup.component.html',
styleUrls: ['./signup.component.scss']
})
export class SignupComponent {
form: FormGroup;
constructor() {
this.init();
}
init() {
this.form = this.fb.group({
name: ['', [Validators.required]],
email: ['', [Validators.required, Validators.email],
password: ['', [
Validators.required,
Validators.pattern('((?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,30})')
]]
});
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…