Guides
Last updated
July 25, 2025

5 Ways to Implement Email Validation in Angular Reactive Forms

Nicolas Rios
Nicolas Rios
Table of Contents:
ON THIS PAGE
Get your free
email validation
 API key now
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
START FOR FREE
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required

Email validation is a basic requirement for data integrity in Angular reactive forms. Here are five ways to implement it, complete with code snippets. You will also see the common pitfalls of these traditional methods and how Abstract API offers a solution to these challenges.

How to Implement Email Validation in Angular

Angular offers several built-in and custom methods to validate email inputs in reactive forms. These range from simple pattern checks to more complex synchronous and asynchronous functions for robust validation.

Built-in Email Validator

Angular provides a ready-made function, Validators.email, that you can add to a reactive FormControl. This function uses a regular expression inspired by WHATWG standards to perform the check.

It rejects addresses with a local part over 64 bytes or a total length over 254 bytes. It also flags emails where the local part starts or ends with a dot. As a synchronous validator, it runs on every value change and returns an error object if the pattern fails.

constructor(private fb: FormBuilder) {
  this.form = this.fb.group({
    email: ['', [Validators.required, Validators.email]]
  });
}

Custom Regex with Validators.pattern

When you need to enforce a specific email format, such as one for internal company use, you can use Validators.pattern. This function accepts a custom regular expression to validate the input.

This approach lets you define precise rules. You can permit only certain top-level domains or forbid special characters like the plus sign. The regex can be defined inline or externalized for reuse across your application, as shown in some community examples.

const companyMail = /^[a-z0-9._%+-]+@acme\.corp$/i;
this.form = this.fb.group({
  email: ['', [Validators.required, Validators.pattern(companyMail)]]
});

Custom Synchronous Validator Function

For validation logic that a single regex cannot handle, you can write a custom synchronous validator function. This is useful for more complex scenarios, such as a check against a list of disposable email domains.

The function receives the form control as an argument and should return null if validation passes or an error object if it fails. These functions can be parameterized to create reusable and manageable validators.

function enterpriseEmailValidator(control: AbstractControl) {
  const value = control.value as string;
  if (!/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/i.test(value)) return {invalidFormat: true};
  const [_, domain] = value.split('@');
  if (['mailinator.com','tempmail.dev'].includes(domain)) return {disposable: true};
  return null;
}
this.form = this.fb.group({
  email: ['', [Validators.required, enterpriseEmailValidator]]
});

Custom Asynchronous Validator

To confirm an email's uniqueness or deliverability, you can implement a custom asynchronous validator. This type of validator typically makes an HTTP request to a backend service to check the email against a database.

You attach an AsyncValidatorFn to the form control, which returns an Observable. According to the official documentation, Angular runs async validators only after all synchronous validators have passed. To prevent excessive server requests, you can set the form's updateOn option to 'blur'. This is a common pattern for async validators.

emailTaken(control: AbstractControl) {
  return this.userSvc.isEmailTaken(control.value).pipe(
    map(isTaken => (isTaken ? {taken: true} : null))
  );
}
this.form = this.fb.group({
  email: ['', [Validators.required, Validators.email], [this.emailTaken.bind(this)]],
}, {updateOn: 'blur'});

Challenges of Email Validation in Angular

These built-in and custom approaches present practical hurdles. Developers often face issues with pattern accuracy, maintenance overhead, and performance bottlenecks when they implement these validators.

  • The built-in Validators.email function uses a limited regex. It rejects valid but uncommon addresses, like those with plus-tagged aliases, and permits some non-deliverable strings. This limitation requires fragile custom validators.
  • Hard-coded patterns in Validators.pattern or custom functions quickly become obsolete. They fail to validate new top-level domains and internationalized addresses unless developers perform constant, manual updates to the regular expressions.
  • Custom asynchronous validators for deliverability checks introduce complexity. They require extra logic for observables and error handling to prevent race conditions, since they run only after synchronous validation passes.
  • Complex regular expressions used in Validators.pattern create performance and security risks. A crafted input can cause a Regex-DoS attack that freezes the application, and developers often find mismatches between testers and Angular's parser.

Validate Emails with Abstract API
Improve user sign-ups and data accuracy in your Angular reactive forms with proper email validation.
Get started for free

How Abstract API Handles Email Validation in Angular Reactive Forms

Abstract API addresses the core weaknesses of traditional methods with a comprehensive, real-time validation service through a simple API call.

  • A single HTTPS GET request returns a deliverability classification, a quality score, typo autocorrection, and multiple boolean flags, which removes the need for open ports or custom lists.
  • The service uses machine learning and receives continuous updates, so the validator's logic improves independently of your codebase.
  • Its pure JSON response integrates into an AsyncValidator, and the error object can carry the full API payload to give the UI granular feedback.
  • A constant API surface works identically in the front-end and back-end, which eliminates divergent validation paths.

How to Bring Abstract API to Your Dev Environment

Once you understand Abstract’s capabilities, you can add its email validation API to your project with a few simple steps.

  • Sign up at Abstract and generate an Email Validation API key.
  • Install @angular/common for HttpClient via npm if the project does not already include it.
  • Add HttpClientModule to the imports array in your AppModule.
  • Create an EmailValidationService to send a GET request to the API with your key and the email address.
  • Implement an AsyncValidatorFn that uses the service to validate the email. It should return null for valid addresses or an error object for invalid ones.
  • Attach the validator to the email form control and set the update trigger to blur.
@Injectable({providedIn:'root'})
export class EmailValidationService {
  private url = 'https://emailvalidation.abstractapi.com/v1/';
  constructor(private http: HttpClient) {}
  validate(email: string) {
    return this.http.get<any>(this.url, {params: {api_key: environment.abstractKey, email}});
  }
}

Sample Email Validation Implementation with Abstract API

The code below defines a custom asynchronous validator, emailDeliverabilityValidator. This function uses the EmailValidationService to call the API. It then inspects the API response. If the email's deliverability status is DELIVERABLE and it is not a disposable address, the function returns null to signal success. Otherwise, it returns an error object that contains the full API response, which you can use to show detailed feedback in the UI.

export const emailDeliverabilityValidator =
  (svc: EmailValidationService): AsyncValidatorFn => (ctrl) =>
    svc.validate(ctrl.value).pipe(
      map(r => r.deliverability === 'DELIVERABLE' && !r.is_disposable_email.value ? null : {abstractEmail: r}),
      catchError(() => of({abstractEmail: {error: 'apiFailure'}}))
    );

A successful validation for a legitimate email address returns a JSON object like this:

{
 "email":"johnsmith@gmail.com",
 "autocorrect":"",
 "deliverability":"DELIVERABLE",
 "quality_score":0.9,
 "is_valid_format":{"value":true,"text":"TRUE"},
 "is_free_email":{"value":true,"text":"TRUE"},
 "is_disposable_email":{"value":false,"text":"FALSE"},
 "is_role_email":{"value":false,"text":"FALSE"},
 "is_catchall_email":{"value":false,"text":"FALSE"},
 "is_mx_found":{"value":true,"text":"TRUE"},
 "is_smtp_valid":{"value":true,"text":"TRUE"}
}
  • deliverability: This field tells you if an email is safe to accept.
  • quality_score: This score from 0 to 0.99 offers a numeric threshold for finer control over email acceptance.
  • boolean flags: Fields like is_disposable_email let you build custom logic and UI messages without another API call.

Final Thoughts

Traditional email validation in Angular often relies on pattern checks that cannot detect bad domains or temporary addresses. A custom server-side validator introduces slowness and maintenance burdens. Abstract API replaces these flawed methods with a single, fast API call for comprehensive, real-time validation.

For reliable user email validation, consider a free account with Abstract API to get your API key.

Validate Emails with Abstract API
Ensure every email is valid. Protect your forms from bad data and improve user sign-ups.
Get started for free

Related Articles

Phone Validation
key now
Get your free
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required