英文:
when try to add confirm mail function group get error Expected 1-2 arguments but got 3. ts(2554)?
问题
问题
在将确认电子邮件作为第三个参数添加时,出现错误"Expected 1-2 arguments but got 3. ts(2554)"?
我在使用 Angular 7 开发时创建了用户注册表单。
当进行验证时,将用户邮件与确认邮件进行比较时,Reactive 表单中的函数组不接受将邮件确认作为参数添加,如下所示的代码。
那么如何在注册表单中添加确认电子邮件?
import { MustMatchEmail } from '../helpers/EmailValidator';
import { MustMatch } from '../helpers/must-match.validator';
constructor() {}
UserMail = new FormControl('', [Validators.required, Validators.email, Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$'), Validators.maxLength(100)]);
ConfirmedEmail = new FormControl('', [Validators.required, Validators.email, Validators.maxLength(100)])
ngOnInit() {
this.createFormValidations();
}
createFormValidations() {
this.registerForm = this.formBuilder.group({
UserMail: this.UserMail,
ConfirmedEmail: this.ConfirmedEmail,
UserPass: this.UserPass,
ConfirmedPassword: this.ConfirmedPassword,
}, {
validator: MustMatch('UserPass', 'ConfirmedPassword')
},
// 这里出现错误,函数不接受邮件确认
{
validator: MustMatchEmail('UserMail', 'ConfirmedEmail')
}
);
}
英文:
Problem
error Expected 1-2 arguments but got 3. ts(2554) when add confirm email as third argument ?
I work on angular 7 I make register users form
when do validation compare user mail to confirm mail on Reactive form .
function group not accept to add argument for mail confirm as code below
so How to add confirm email on register form ?
import {MustMatchEmail} from '../helpers/EmailValidator';
import {MustMatch} from '../helpers/must-match.validator';
constructor() {}
UserMail = new FormControl('', [Validators.required, Validators.email, Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$'), Validators.maxLength(100)]);
ConfirmedEmail = new FormControl('', [Validators.required, Validators.email, Validators.maxLength(100)])
ngOnInit() {
this.createFormValidations();
}
createFormValidations() {
this.registerForm = this.formBuilder.group({
UserMail: this.UserMail,
ConfirmedEmail: this.ConfirmedEmail,
UserPass: this.UserPass,
ConfirmedPassword: this.ConfirmedPassword,
}, {
validator: MustMatch('UserPass', 'ConfirmedPassword')
},
//here error function not accept mail confirm
{
validator: MustMatchEmail('UserMail', 'ConfirmedEmail')
}
);
}
答案1
得分: 1
Reference: https://alligator.io/angular/reactive-forms-custom-validator/
this.registerForm = this.formBuilder.group({
userMail: [this.userMail, MustMatchEmail('UserMail', 'ConfirmedMail')],
});
英文:
Try this: Reference: https://alligator.io/angular/reactive-forms-custom-validator/
this.registerForm = this.formBuilder.group({
userMail: [this.userMail, MustMatchEmail('UserMail','ConfirmedMail')],
});
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论