Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!PhoneValidators.checkRegionCode(local)) {
return { 'noValidRegionCode': true };
}
let phoneParser: PhoneNumberUtil = PhoneNumberUtil.getInstance();
let error: any = { 'noPhoneNumber': true };
try {
let phoneNumber: libPhoneNumber.PhoneNumber = phoneParser.parse(control.value, local);
let reason: PhoneNumberUtil.ValidationResult = phoneParser.isPossibleNumberWithReason(phoneNumber);
switch (reason) {
case PhoneNumberUtil.ValidationResult.IS_POSSIBLE:
error = undefined;
break;
case PhoneNumberUtil.ValidationResult.TOO_LONG:
error = { 'phoneNumberTooLong': true };
break;
case PhoneNumberUtil.ValidationResult.TOO_SHORT:
error = { 'phoneNumberTooShort': true };
break;
case PhoneNumberUtil.ValidationResult.INVALID_COUNTRY_CODE:
error = { 'phoneNumberInvalidCountryCode': true };
break;
default:
error = { 'noPhoneNumber': true };
break;
}
} catch (err) {
error = { 'noPhoneNumber': true };
}