2017-05-24 6 views
0

Reactiveフォームを使用してAngularでユーザー登録フォームを作成しようとしています。 大文字で始まり、少なくとも1つの数字、少なくとも1つの特殊文字、小文字の制限がないように、パスワードの検証が必要です。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)) 
} 

答えて

1

上記の私の要件については、あなたが探しているパターンが

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

あるいはそれに近いです。それはあなたが代わりに `{1}`先読み中の `` *使用する必要があなたの特別な文字とあなたの数

+0

を見つけるためにpositive lookaheadを使用しています。そうでなければ、それはノーオペレーションです - 特に指定されていない限り、すべてのトークンは一度だけ一致しますので、いつでもドロップすることができます。 –

関連する問題