Beispiel #1
0
    def __init__(self, country):
        codes = tel.region_codes_for_country_code(country)
        if not codes:
            raise ValueError('Invalid country code {}'.format(country))
        self.region = random.choice(codes)

        ph = tel.example_number(self.region)
        bits = len(str(ph.national_number)) + 1
        super().__init__(bits)
    def __init__(self, *args, region=None, **kwargs):
        super().__init__(*args, **kwargs)
        self.widget.input_type = "tel"

        validate_region(region)
        self.region = region

        if "invalid" not in self.error_messages:
            if region:
                number = phonenumbers.example_number(region)
                example_number = to_python(number).as_national
                # Translators: {example_number} is a national phone number.
                error_message = _(
                    "Enter a valid phone number (e.g. {example_number}) "
                    "or a number with an international call prefix.")
            else:
                example_number = "+12125552368"  # Ghostbusters
                # Translators: {example_number} is an international phone number.
                error_message = _(
                    "Enter a valid phone number (e.g. {example_number}).")
            self.error_messages["invalid"] = format_lazy(
                error_message, example_number=example_number)
Beispiel #3
0
import phonenumbers
x = phonenumbers.parse("+442083661177", None)
G=phonenumbers.example_number("+442083661177")
print(G)
type(x)

y = phonenumbers.parse("020 8366 1177", "GB")
print("h",y)
print(x == y)

# as dialed from GB, not a GB number
z = phonenumbers.parse("00 1 650 253 2222", "GB")
print(z)


z = phonenumbers.parse("+120012301", None)
phonenumbers.is_valid_number(z)