import { FormControl, ValidationErrors } from '@angular/forms';

const EMAIL_REGEXP = /^(?=.{1,254}$)(?=.{1,64}@)[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/;
export function validateEmail(c: FormControl): ValidationErrors | null {
  return c.value == null || c.value === '' || EMAIL_REGEXP.test(c.value) ? null : { invalid: 'E-Mail ist ungültig' };
}
