0
votes

I am having two inputs, one with country code options like CA, US and so on and another with mobile number. I saw in some of the source to use google-libphonenumber for validation and i find a custom validation for that in Use google-libphonenumber in angular reactive forms validator , using this custom validator bring me some errors in return validNumber ? null : { 'wrongNumber': { value: control.value } };

Type '{ wrongNumber: { value: any; }; } | null' is not assignable to type '{ [key: string]: any; }'. Type 'null' is not assignable to type '{ [key: string]: any; }'.

how to pass the country code and mobile number to validate and if invalidate show error in the html pass.

1

1 Answers

0
votes

In your function PhoneNumberValidator, try to change:

return (control: AbstractControl): { [key: string]: any } => {

for

return (control: AbstractControl): { [key: string]: any } | null => {

If it doesn't work, try this another one change, alone (or mix it):

export function PhoneNumberValidator(regionCode?: string): (ValidatorFn | null | undefined)): ValidatorFn {