Skip to content

Instantly share code, notes, and snippets.

@ihsanberahim
Created July 21, 2020 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihsanberahim/585061b8bce25bcaeabdd9aad6ad3bfe to your computer and use it in GitHub Desktop.
Save ihsanberahim/585061b8bce25bcaeabdd9aad6ad3bfe to your computer and use it in GitHub Desktop.
Custom Proper email validation
import { AbstractControl } from '@angular/forms';
export function ValidateProperEmail(control: AbstractControl) {
const error = { properEmail: true };
if (!control.value) {
return error;
}
if (!control.value.includes('@')) {
return error;
}
const domain = control.value.split('@')[1];
if (!domain.includes('.')) {
return error;
}
const tld = domain.split('.')[
domain.split('.').length - 1
];
if (!tld.match(/^[A-Za-z]+$/)) {
return error;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment