1.  
  2. /** A hero's name can't match the given regular expression */
  3. export function forbiddenNameValidator(nameRe: RegExp): ValidatorFn {
  4. return (control: AbstractControl): {[key: string]: any} | null => {
  5. const forbidden = nameRe.test(control.value);
  6. return forbidden ? {'forbiddenName': {value: control.value}} : null;
  7. };
  8. }
  9.