import { ValidationErrors, AbstractControl } from '@angular/forms'; // tslint:disable-next-line:max-line-length const RE: RegExp = new RegExp( "^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$" ); /** * Validates an email address using the same regular expression the server uses. * * @param email the form control to validate */ export function emailValidator(email: AbstractControl): ValidationErrors { const value = email.value; if (!value) { return null; } return RE.test(email.value) ? null : { email: true, validateEmail: { valid: false } }; }