我正在尝试使用反应式表单在 Angular 中创建用户注册表单。我希望密码验证应该以大写字母开头,至少有一个数字,至少一个特殊字符,并且对小写字母没有限制。
我所拥有的是:
ngOnInit(): void {
this.customerForm = this.fb.group({ //root group [formGroup]
firstName: ['', [Validators.required, Validators.minLength(3)]],
lastName: ['', [Validators.required, Validators.minLength(2), Validators.maxLength(50)]],
password: ['',[Validators.required, Validators.minLength(6), Validators.maxLength(25), Validators.pattern('')]],
// Validators.pattern('' )
在这里我需要使用回归表达式,但我不知道哪一个适合我的上述要求
emailGroup: this.fb.group({
email: [null, [Validators.required, Validators.pattern("[a-z0-9._%+-]+@[a-z0-9.-]+")]],
confirmEmail: ['', Validators.required],
}, { validator: emailMatcher }),
country: [null, [Validators.required]],
})
let getNotification = this.customerForm.get('notification')
getNotification.valueChanges
.subscribe(value => this.sentNotification(value)) //subscribe is like a for each so it displays the output
const emailControl = this.customerForm.get('emailGroup.email');
emailControl.valueChanges
.debounceTime(1000)
.subscribe(value =>
this.setMessageForEmail(emailControl));
const firstNameControl = this.customerForm.get('firstName')
firstNameControl.valueChanges
.subscribe(value =>
this.setMessageForFirstName(firstNameControl))
}