0
我正嘗試在Angular中使用Reactive形式創建用戶註冊表單。 我想要密碼驗證,就像它應該以大寫字母開頭,至少有一個數字,至少有一個特殊字符,並且對小寫字母沒有限制。Angular2中的密碼字段的迴歸表達式
我所擁有的是:
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._%+-][email protected][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))
}
您需要在lookahead中使用'*'而不是'{1}'。否則,它是一個無操作 - 除非另有指定,否則每個標記都只匹配一次,因此您可以隨時刪除它。 –