當前位置: 首頁>>代碼示例>>Python>>正文


Python phonenumbers.is_possible_number方法代碼示例

本文整理匯總了Python中phonenumbers.is_possible_number方法的典型用法代碼示例。如果您正苦於以下問題:Python phonenumbers.is_possible_number方法的具體用法?Python phonenumbers.is_possible_number怎麽用?Python phonenumbers.is_possible_number使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在phonenumbers的用法示例。


在下文中一共展示了phonenumbers.is_possible_number方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: normalize_phone

# 需要導入模塊: import phonenumbers [as 別名]
# 或者: from phonenumbers import is_possible_number [as 別名]
def normalize_phone(cls, number):
        """
        Normalizes the passed in phone number
        """
        # remove any invalid characters
        number = regex.sub(r"[^0-9a-z\+]", "", number.lower(), regex.V0)

        # add on a plus if it looks like it could be a fully qualified number
        if len(number) >= 11 and number[0] not in ["+", "0"]:
            number = "+" + number

        try:
            normalized = phonenumbers.parse(number)

            if phonenumbers.is_possible_number(normalized):
                return phonenumbers.format_number(normalized, phonenumbers.PhoneNumberFormat.E164)
        except Exception:
            pass

        return number 
開發者ID:rapidpro,項目名稱:casepro,代碼行數:22,代碼來源:models.py

示例2: validate_phone

# 需要導入模塊: import phonenumbers [as 別名]
# 或者: from phonenumbers import is_possible_number [as 別名]
def validate_phone(cls, number):
        """
        Validates the given phone number which should be in E164 format.
        """
        try:
            parsed = phonenumbers.parse(number)
        except phonenumbers.NumberParseException as e:
            raise InvalidURN(str(e))

        if number != phonenumbers.format_number(parsed, phonenumbers.PhoneNumberFormat.E164):
            raise InvalidURN("Phone numbers must be in E164 format")

        if not phonenumbers.is_possible_number(parsed) or not phonenumbers.is_valid_number(parsed):
            raise InvalidURN("Phone numbers must be in E164 format")

        return True 
開發者ID:rapidpro,項目名稱:casepro,代碼行數:18,代碼來源:models.py

示例3: phone_number_is_valid

# 需要導入模塊: import phonenumbers [as 別名]
# 或者: from phonenumbers import is_possible_number [as 別名]
def phone_number_is_valid(number, country=None):
    """Given a phone number and a country code, returns True if the phone number is valid, otherwise False."""
    ensure_definition(number, country)
    if country is None:
        country = get_country()
    if isinstance(number, str):
        m = re.search(r'^whatsapp:(.*)', number)
        if m:
            number = m.group(1)
    try:
        pn = phonenumbers.parse(number, country)
    except:
        return False
    if phonenumbers.is_possible_number(pn) and phonenumbers.is_valid_number(pn):
        return True
    return False 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:18,代碼來源:functions.py

示例4: validate_phone_number

# 需要導入模塊: import phonenumbers [as 別名]
# 或者: from phonenumbers import is_possible_number [as 別名]
def validate_phone_number(form, field):
    try:
        number = phonenumbers.parse(field.data, "US")

    except phonenumbers.NumberParseException:
        raise wtforms.ValidationError(
            f"{field.data} does not appear to be a valid number."
        )

    if not phonenumbers.is_possible_number(number):
        raise wtforms.ValidationError(
            f"{field.data} does not appear to be a possible number."
        )

    field.data = phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.E164) 
開發者ID:theacodes,項目名稱:conducthotline.com,代碼行數:17,代碼來源:forms.py

示例5: localScan

# 需要導入模塊: import phonenumbers [as 別名]
# 或者: from phonenumbers import is_possible_number [as 別名]
def localScan(InputNumber):
    global number
    global localNumber
    global internationalNumber
    global numberCountryCode
    global numberCountry

    print(code_info + 'Running local scan...')

    FormattedPhoneNumber = "+" + formatNumber(InputNumber)

    try:
        PhoneNumberObject = phonenumbers.parse(FormattedPhoneNumber, None)
    except:
        return False
    else:
        if not phonenumbers.is_valid_number(PhoneNumberObject):
            return False

        number = phonenumbers.format_number(PhoneNumberObject, phonenumbers.PhoneNumberFormat.E164).replace('+', '')
        numberCountryCode = phonenumbers.format_number(PhoneNumberObject, phonenumbers.PhoneNumberFormat.INTERNATIONAL).split(' ')[0]

        countryRequest = json.loads(requests.request('GET', 'https://restcountries.eu/rest/v2/callingcode/{}'.format(numberCountryCode.replace('+', ''))).content)
        numberCountry = countryRequest[0]['alpha2Code']

        localNumber = phonenumbers.format_number(PhoneNumberObject, phonenumbers.PhoneNumberFormat.E164).replace(numberCountryCode, '')
        internationalNumber = phonenumbers.format_number(PhoneNumberObject, phonenumbers.PhoneNumberFormat.INTERNATIONAL)

        print(code_result + 'International format: {}'.format(internationalNumber))
        print(code_result + 'Local format: 0{}'.format(localNumber))
        print(code_result + 'Country code: {}'.format(numberCountryCode))
        print(code_result + 'Location: {}'.format(geocoder.description_for_number(PhoneNumberObject, "en")))
        print(code_result + 'Carrier: {}'.format(carrier.name_for_number(PhoneNumberObject, 'en')))
        print(code_result + 'Area: {}'.format(geocoder.description_for_number(PhoneNumberObject, 'en')))
        for timezoneResult in timezone.time_zones_for_number(PhoneNumberObject):
            print(code_result + 'Timezone: {}'.format(timezoneResult))

        if phonenumbers.is_possible_number(PhoneNumberObject):
            print(code_info + 'The number is valid and possible.')
        else:
            print(code_warning + 'The number is valid but might not be possible.') 
開發者ID:la-deep-web,項目名稱:Phoneinfoga,代碼行數:43,代碼來源:phoneinfoga.py

示例6: localScan

# 需要導入模塊: import phonenumbers [as 別名]
# 或者: from phonenumbers import is_possible_number [as 別名]
def localScan(InputNumber, print_results=True):
    print("Running local scan...")

    FormattedPhoneNumber = "+" + formatNumber(InputNumber)

    try:
        PhoneNumberObject = phonenumbers.parse(FormattedPhoneNumber, None)
    except Exception as e:
        print(e)
    else:
        if not phonenumbers.is_valid_number(PhoneNumberObject):
            return False

        number = phonenumbers.format_number(PhoneNumberObject, phonenumbers.PhoneNumberFormat.E164).replace("+", "")
        numberCountryCode = phonenumbers.format_number(PhoneNumberObject, phonenumbers.PhoneNumberFormat.INTERNATIONAL).split(" ")[0]
        numberCountry = phonenumbers.region_code_for_country_code(int(numberCountryCode))

        localNumber = phonenumbers.format_number(PhoneNumberObject, phonenumbers.PhoneNumberFormat.E164).replace(numberCountryCode, "")
        internationalNumber = phonenumbers.format_number(PhoneNumberObject, phonenumbers.PhoneNumberFormat.INTERNATIONAL)

        country = geocoder.country_name_for_number(PhoneNumberObject, "en")
        location = geocoder.description_for_number(PhoneNumberObject, "en")
        carrierName = carrier.name_for_number(PhoneNumberObject, "en")

        if print_results:
            print("International format: {}".format(internationalNumber))
            print("Local format: {}".format(localNumber))
            print("Country found: {} ({})".format(country, numberCountryCode))
            print("City/Area: {}".format(location))
            print("Carrier: {}".format(carrierName))
            for timezoneResult in timezone.time_zones_for_number(PhoneNumberObject):
                print("Timezone: {}".format(timezoneResult))

            if phonenumbers.is_possible_number(PhoneNumberObject):
                print("The number is valid and possible.")
            else:
                print("The number is valid but might not be possible.")

    numberObj = {}
    numberObj["input"] = InputNumber
    numberObj["default"] = number
    numberObj["local"] = localNumber
    numberObj["international"] = internationalNumber
    numberObj["country"] = country
    numberObj["countryCode"] = numberCountryCode
    numberObj["countryIsoCode"] = numberCountry
    numberObj["location"] = location
    numberObj["carrier"] = carrierName

    return numberObj 
開發者ID:rpotter12,項目名稱:whatsapp-play,代碼行數:52,代碼來源:target_info.py

示例7: smsnumber_to_e164

# 需要導入模塊: import phonenumbers [as 別名]
# 或者: from phonenumbers import is_possible_number [as 別名]
def smsnumber_to_e164(smsnumber, iso2countrycode):
    """Tries to convert a string into an E.164 formatted phone number
       Raises exception if it can't, returns the E.164 number as a string, if it can """

    try:
        log.logger.debug(u'Converting {} to E.164 format, country code {}'.format(smsnumber, iso2countrycode))

        try:
            if smsnumber.startswith('+'):
                smsnumber_obj = phonenumbers.parse(smsnumber)
            else:
                # country code not specified in number, so pass it in
                smsnumber_obj = phonenumbers.parse(smsnumber, iso2countrycode)
        except phonenumbers.NumberParseException as e:
            errormessage = u'SMS Unable to parse number {}. Error: {}'.format(smsnumber, e.message)
            log.logger.error(errormessage)
            raise UserWarning(errormessage)

        try:
            if not phonenumbers.is_possible_number(smsnumber_obj):
                errormessage = u'SMS Number is not possibly valid: {}.'.format(smsnumber)
                log.logger.error(errormessage)
                raise UserWarning(errormessage)
        except phonenumbers.NumberParseException as e:
            errormessage = u'SMS Unable to parse number {}. Error: {}'.format(smsnumber, e.message)
            log.logger.error(errormessage)
            raise UserWarning(errormessage)

        if not phonenumbers.is_valid_number(smsnumber_obj):
            errormessage = u'SMS Number is not valid: {}.'.format(smsnumber)
            log.logger.error(errormessage)
            raise UserWarning(errormessage)


        e164_number = phonenumbers.format_number(smsnumber_obj, phonenumbers.PhoneNumberFormat.E164)
        if not e164_number:
            errormessage = u'SMS number {} could not be converted to E.164 for an unknown reason.'.format(smsnumber)
            log.logger.error(errormessage)
            raise UserWarning(errormessage)

        # all good, return it!
        return e164_number
    except Exception as e:
        log.logger.error(e.message)
        return None 
開發者ID:tableau,項目名稱:VizAlerts,代碼行數:47,代碼來源:smsaction.py

示例8: scan

# 需要導入模塊: import phonenumbers [as 別名]
# 或者: from phonenumbers import is_possible_number [as 別名]
def scan(InputNumber, print_results=True):
    test('Running local scan...')

    FormattedPhoneNumber = "+" + formatNumber(InputNumber)

    try:
        PhoneNumberObject = phonenumbers.parse(FormattedPhoneNumber, None)
    except Exception as e:
        throw(e)
    else:
        if not phonenumbers.is_valid_number(PhoneNumberObject):
            return False

        number = phonenumbers.format_number(
            PhoneNumberObject, phonenumbers.PhoneNumberFormat.E164).replace('+', '')
        numberCountryCode = phonenumbers.format_number(
            PhoneNumberObject, phonenumbers.PhoneNumberFormat.INTERNATIONAL).split(' ')[0]
        numberCountry = phonenumbers.region_code_for_country_code(
            int(numberCountryCode))

        localNumber = phonenumbers.format_number(
            PhoneNumberObject, phonenumbers.PhoneNumberFormat.E164).replace(numberCountryCode, '')
        internationalNumber = phonenumbers.format_number(
            PhoneNumberObject, phonenumbers.PhoneNumberFormat.INTERNATIONAL)

        country = geocoder.country_name_for_number(PhoneNumberObject, "en")
        location = geocoder.description_for_number(PhoneNumberObject, "en")
        carrierName = carrier.name_for_number(PhoneNumberObject, 'en')

        if print_results:
            info('International format: {}'.format(internationalNumber))
            info('Local format: {}'.format(localNumber))
            info('Country found: {} ({})'.format(country, numberCountryCode))
            info('City/Area: {}'.format(location))
            info('Carrier: {}'.format(carrierName))
            for timezoneResult in timezone.time_zones_for_number(PhoneNumberObject):
                info('Timezone: {}'.format(timezoneResult))

            if phonenumbers.is_possible_number(PhoneNumberObject):
                plus('The number is valid and possible!')
            else:
                warn('The number is valid but might not be possible.')

    numberObj = {}
    numberObj['input'] = InputNumber
    numberObj['default'] = number
    numberObj['local'] = localNumber
    numberObj['international'] = internationalNumber
    numberObj['country'] = country
    numberObj['countryCode'] = numberCountryCode
    numberObj['countryIsoCode'] = numberCountry
    numberObj['location'] = location
    numberObj['carrier'] = carrierName

    return numberObj 
開發者ID:entynetproject,項目名稱:phonia,代碼行數:57,代碼來源:localscan.py


注:本文中的phonenumbers.is_possible_number方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。