From 91b591a800b21c77fc28e0513d8d8d0e3fb4dddb Mon Sep 17 00:00:00 2001 From: salacis Date: Wed, 9 Aug 2017 20:13:39 +0200 Subject: [PATCH] Added multiple country validation --- src/phone/validator.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/phone/validator.ts b/src/phone/validator.ts index 60fd43b..ab2423c 100644 --- a/src/phone/validator.ts +++ b/src/phone/validator.ts @@ -1,14 +1,14 @@ import { AbstractControl, Validators, ValidatorFn } from '@angular/forms'; -import { isValidNumber } from 'libphonenumber-js'; +import { isValidNumber, CountryCode } from 'libphonenumber-js'; import { isPresent } from '../util/lang'; -export const phone = (country: string): ValidatorFn => { +export const phone = (...country: string[]): ValidatorFn => { return (control: AbstractControl): { [key: string]: boolean } => { if (isPresent(Validators.required(control))) return null; - let v: string = control.value; - - return isValidNumber({phone: v, country}) ? null : {phone: true}; + return (country.some(c => { + return isValidNumber(control.value, c as CountryCode); + })) ? null : {phone: true}; }; };