custom validator

import {Component} from '@angular/core';
import { FormGroup, FormControl,
         FormBuilder, Validators, FormArray, ValidatorFn, AbstractControl } from '@angular/forms';
@Component({
  selector: 'my-app',
  template: `
        <form [formGroup]="myForm" (ngSubmit)="show()">
      <input id="email" name="email" type="email" [formControl]="email" />
      <span *ngIf="email.errors?.required">メールアドレスは必須です。</span>
      <p *ngIf="email.errors?.emailDomain">Email must be on the codecraft.tv domain</p>
    </form>
        `
})
export class AppComponent  {
    email = new FormControl('', [
    Validators.required,
    Validators.pattern("[^ @]*@[^ @]*"),
    emailDomainValidator
  ]);
  myForm = this.builder.group({
    email: this.email,
  });
  constructor(private builder: FormBuilder) { }
}

export function emailDomainValidator(control: FormControl) { 
  let email = control.value; 
  if (email && email.indexOf("@") != -1) { 
    let [_, domain] = email.split("@"); 
    if (domain !== "com") { 
      return {
        emailDomain: {
          parsedDomain: domain
        }
      }
    }
  }
  return null; 
}