0

我正在尝试使用反应式表单在 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))
}
4

1 回答 1

1

您正在寻找的模式是

[A-Z](?=.*\d)(?=.*[---ALL YOUR SPECIAL CHARS HERE])(?=.*[a-z])

或者接近那个。它使用积极的前瞻来查找您的特殊字符和您的号码

于 2017-05-24T10:31:04.313 回答