How to use the google-libphonenumber.PhoneNumberUtil.ValidationResult function in google-libphonenumber

To help you get started, we’ve selected a few google-libphonenumber examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Nightapes / ngx-validators / src / components / phone / phone-validators.ts View on Github external
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 };
            }