Exemple #1
0
        /**
         * Tests whether a short number matches a valid pattern in a region. Note that this doesn't verify
         * the number is actually in use, which is impossible to tell by just looking at the number
         * itself.
         *
         * @param shortNumber the short number to check as a string
         * @param regionDialingFrom the region from which the number is dialed
         * @return whether the short number matches a valid pattern
         */
        public bool isValidShortNumberForRegion(String shortNumber, String regionDialingFrom)
        {
            PhoneMetadata phoneMetadata =
                MetadataManager.getShortNumberMetadataForRegion(regionDialingFrom);

            if (phoneMetadata == null)
            {
                return(false);
            }
            PhoneNumberDesc generalDesc = phoneMetadata.getGeneralDesc();

            if (!generalDesc.HasNationalNumberPattern() ||
                !phoneUtil.isNumberMatchingDesc(shortNumber, generalDesc))
            {
                return(false);
            }
            PhoneNumberDesc shortNumberDesc = phoneMetadata.getShortCode();

            if (!shortNumberDesc.HasNationalNumberPattern())
            {
                logger.log(Level.WARNING, "No short code national number pattern found for region: " +
                           regionDialingFrom);
                return(false);
            }
            return(phoneUtil.isNumberMatchingDesc(shortNumber, shortNumberDesc));
        }
Exemple #2
0
        /**
         * Check whether a short number is a possible number when dialled from a region, given the number
         * in the form of a string, and the region where the number is dialed from. This provides a more
         * lenient check than {@link #isValidShortNumberForRegion}.
         *
         * @param shortNumber the short number to check as a string
         * @param regionDialingFrom the region from which the number is dialed
         * @return whether the number is a possible short number
         */
        public bool isPossibleShortNumberForRegion(String shortNumber, String regionDialingFrom)
        {
            PhoneMetadata phoneMetadata =
                MetadataManager.getShortNumberMetadataForRegion(regionDialingFrom);

            if (phoneMetadata == null)
            {
                return(false);
            }
            PhoneNumberDesc generalDesc = phoneMetadata.getGeneralDesc();

            return(phoneUtil.isNumberPossibleForDesc(shortNumber, generalDesc));
        }
Exemple #3
0
        /**
         * Check whether a short number is a possible number. If a country calling code is shared by
         * multiple regions, this returns true if it's possible in any of them. This provides a more
         * lenient check than {@link #isValidShortNumber}. See {@link
         * #isPossibleShortNumberForRegion(String, String)} for details.
         *
         * @param number the short number to check
         * @return whether the number is a possible short number
         */
        public bool isPossibleShortNumber(PhoneNumber number)
        {
            List <String> regionCodes = phoneUtil.getRegionCodesForCountryCode(number.getCountryCode());
            String        shortNumber = phoneUtil.getNationalSignificantNumber(number);

            foreach (String region in regionCodes)
            {
                PhoneMetadata phoneMetadata = MetadataManager.getShortNumberMetadataForRegion(region);
                if (phoneUtil.isNumberPossibleForDesc(shortNumber, phoneMetadata.getGeneralDesc()))
                {
                    return(true);
                }
            }
            return(false);
        }