Я пытаюсь реализовать пользовательскую угловую функцию для проверки адреса электронной почты, все хорошо, кроме случаев, когда я набираю example @ mail, проверка не работает, и адрес электронной почты считается действительным
Validator.ts
static emailsLenghtAndFormat(control: AbstractControl): ValidationErrors | null {
const email = control.value;
const responseKo = { invalid: true };
const responseOk = null;
const responseKoMaxLength = { maxlength: true };
if (!email) {
return responseOk;
}
if (email.length > 100) {
return responseKoMaxLength;
}
const EMAIL_REGEXP = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
if (email !== '' && (email.length <= 5 || !EMAIL_REGEXP.test(email))) {
return responseKo;
}
return responseOk;
}
authenticnt.ts
this.formAuthentification = this.fb.group({
authentification: this.fb.group(
{
email: ['', [Validators.required, Validators.email, Validators.maxLength(100)]],
password: ['', Validators.required],
},
{
validator: [ValidatorsCustom.emailsLenghtAndFormat]
}
)
});