import { AbstractControl, Validators, ValidatorFn } from '@angular/forms';

import { isPresent } from '../../integer';

export const digits: ValidatorFn = (control: AbstractControl): {[key: string]: boolean} => {
  if (isPresent(Validators.required(control))) return null;

  let v: string = control.value;
  return /^\d+$/.test(v) ? null : {digits: true};
};
