Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created January 7, 2018 19:07
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 uno-de-piera/d5b27cf21448240896c8344fc579637c to your computer and use it in GitHub Desktop.
Save uno-de-piera/d5b27cf21448240896c8344fc579637c to your computer and use it in GitHub Desktop.
Validar número teléfono Angular 5
import {AbstractControl, ValidatorFn} from '@angular/forms';
export function phoneValidator(phoneExp: RegExp): ValidatorFn {
return (control: AbstractControl): {[key: string]: any} => {
const phone = phoneExp.test(control.value);
return !phone ? {'phoneNumber': {value: control.value}} : null;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment