0
可以任何一個幫助我進行此驗證,我不瞭解this.i新到這個angular2和ionic2。如何使用這個customvalidators,請幫助我密碼匹配(密碼和確認密碼)驗證使用ionic2和angular2
<form [formGroup]="passwordForm">
<ion-list formGroupName="password">
<ion-item>
<ion-label floating>Old Password</ion-label>
<ion-input type="text" value="" formControlName="oldpassword" [(ngModel)]="oldPasswd" required></ion-input>
</ion-item>
<ion-list formGroupName="matchingPassword">
<ion-item>
<ion-label floating>New Password</ion-label>
<ion-input type="text" value="" formControlName="newpassword" [(ngModel)]="newPasswd" required></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Re-Enter Password</ion-label>
<ion-input type="text" value="" formControlName="reenterpassword" [(ngModel)]="rePasswd" required></ion-input>
</ion-item><br><br>
</ion-list>
</ion-list>
</form>
<button small (click)="changPassword();">Change Password</button>
的.ts
constructor(private navCtrl: NavController, private users:Users,public _form: FormBuilder) {
this.passwordForm = new FormGroup({
password: new FormGroup({
oldpassword: new FormControl('', [Validators.required,Validators.minLength(5),Validators.maxLength(10)]),
matchingPassword: new FormGroup({
newpassword: new FormControl('', [Validators.required,Validators.minLength(5),Validators.maxLength(10)]),
reenterpassword: new FormControl('', this.customValidator),
},,{validator: this.isEqual})
})
});
}
private customValidator(control: FormControl) {
// check if control is equal to the password1 control
return {isEqual: control.value === this.passwordForm.controls['newpassword'].value};
}