From 0c67dc6130324162b032508c9c528eb8e27ce4c0 Mon Sep 17 00:00:00 2001 From: Victor Korzunin Date: Fri, 4 Aug 2017 19:14:56 +0500 Subject: [PATCH 1/2] Fixed formated phone numbers validation --- src/phone/validator.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/phone/validator.ts b/src/phone/validator.ts index 60fd43b..2260834 100644 --- a/src/phone/validator.ts +++ b/src/phone/validator.ts @@ -7,8 +7,6 @@ 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 isValidNumber(control.value, country) ? null : {phone: true}; }; }; From ccc3a0fa8a577aacf4c7be7ea7090a64c0bba244 Mon Sep 17 00:00:00 2001 From: Victor Korzunin Date: Fri, 4 Aug 2017 20:45:31 +0500 Subject: [PATCH 2/2] Cast country variable to CountryCode to elliminate build error --- src/phone/validator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/phone/validator.ts b/src/phone/validator.ts index 2260834..daa0ef3 100644 --- a/src/phone/validator.ts +++ b/src/phone/validator.ts @@ -1,5 +1,5 @@ import { AbstractControl, Validators, ValidatorFn } from '@angular/forms'; -import { isValidNumber } from 'libphonenumber-js'; +import { isValidNumber, CountryCode } from 'libphonenumber-js'; import { isPresent } from '../util/lang'; @@ -7,6 +7,6 @@ export const phone = (country: string): ValidatorFn => { return (control: AbstractControl): { [key: string]: boolean } => { if (isPresent(Validators.required(control))) return null; - return isValidNumber(control.value, country) ? null : {phone: true}; + return isValidNumber(control.value, country as CountryCode) ? null : {phone: true}; }; };