I need to input 50 email addresses with the same domain name (gmail.com).
Currently, I am using a Reactive form but the code I have implemented is not working as expected.
https://stackblitz.com/edit/angular-wfwfow
If anyone could assist me with this, I would greatly appreciate it.
emailPattern = "[a-zA-Z0-9_.+-,;]+@(?:(?:[a-zA-Z0-9-]+\.,;)?[a-zA-Z]+\.,;)?(gmail)\.com";
ngOnInit() {
this.accountingForm = this.fb.group({
'day' : [null, Validators.required],
'email': ['',
Validators.compose([
Validators.required,Validators.pattern(this.emailPattern),this.commaSepEmail
])
]
});
}
commaSepEmail = (control: AbstractControl): { [key: string]: any } | null => {
console.log("This is value:" + control.value);
if (!_.isEmpty(control.value)){
var emails= control.value.split(',');
const forbidden = emails.some((email:any) => Validators.email(new FormControl(email)));
console.log(forbidden);
return forbidden ? { 'email': { value: control.value.trim() } } : null;
}
};
<form [formGroup]="accountingForm" (ngSubmit)="generateSOR(accountingForm.value)">
<input formControlName="email" [pattern]="emailPattern" placeholder="Email Address">
<button type="submit" mat-raised-button class="mat-primary" [disabled]="!accountingForm.valid">Generate</button>
</form>