I have some regular expression validation that I use on email form, this is how it looks
this.customerForm = this.fb.group({
email: [null, {
Validators.pattern('^[^\\s@]+@[^\\s@]+\\.[^\\s@]{1,}$')],updateOn: 'blur'
}]
});
Validation work fine, but what i need is to make custom validator for this regular expression, any idea how to start, thanks
I have tried like this
properEmailValidator(): ValidatorFn {
const nameRe = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{1,}$/;
return (control: AbstractControl): ValidationErrors | null => {
const forbidden = nameRe.test(control.value);
return forbidden ? { emailNotValid: { value: control.value } } : null;
};
}
But this does not work:(