1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module phonenumbers.phonenumberutil</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="phonenumbers.html"><font color="#ffffff">phonenumbers</font></a>.phonenumberutil</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="https://github.com/daviddrysdale/python-phonenumbers/blob/dev/python/phonenumbers/phonenumberutil.py">phonenumbers/phonenumberutil.py</a></font></td></tr></table>
<p><tt>Python phone number parsing and formatting library<br>
<br>
If you use this library, and want to be notified about important changes,<br>
please sign up to the libphonenumber mailing list at<br>
https://groups.google.com/forum/#!aboutgroup/libphonenumber-discuss.<br>
<br>
NOTE: A lot of methods in this module require Region Code strings. These must<br>
be provided using CLDR two-letter region-code format. These should be in<br>
upper-case. The list of the codes can be found here:<br>
<a href="http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm">http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm</a></tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="re.html">re</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="builtins.html#Exception">builtins.Exception</a>(<a href="builtins.html#BaseException">builtins.BaseException</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="phonenumbers.phonenumberutil.html#NumberParseException">NumberParseException</a>(<a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a>, <a href="builtins.html#Exception">builtins.Exception</a>)
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="phonenumbers.phonenumberutil.html#MatchType">MatchType</a>
</font></dt><dt><font face="helvetica, arial"><a href="phonenumbers.phonenumberutil.html#PhoneNumberFormat">PhoneNumberFormat</a>
</font></dt><dt><font face="helvetica, arial"><a href="phonenumbers.phonenumberutil.html#PhoneNumberType">PhoneNumberType</a>
</font></dt><dt><font face="helvetica, arial"><a href="phonenumbers.phonenumberutil.html#ValidationResult">ValidationResult</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a>(<a href="builtins.html#object">builtins.object</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="phonenumbers.phonenumberutil.html#NumberParseException">NumberParseException</a>(<a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a>, <a href="builtins.html#Exception">builtins.Exception</a>)
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="MatchType">class <strong>MatchType</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Types of phone number matches.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Class methods defined here:<br>
<dl><dt><a name="MatchType-to_string"><strong>to_string</strong></a>(val)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt><dd><tt>Return a string representation of a <a href="#MatchType">MatchType</a> value</tt></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>EXACT_MATCH</strong> = 4</dl>
<dl><dt><strong>NOT_A_NUMBER</strong> = 0</dl>
<dl><dt><strong>NO_MATCH</strong> = 1</dl>
<dl><dt><strong>NSN_MATCH</strong> = 3</dl>
<dl><dt><strong>SHORT_NSN_MATCH</strong> = 2</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="NumberParseException">class <strong>NumberParseException</strong></a>(<a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a>, <a href="builtins.html#Exception">builtins.Exception</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt><a href="#NumberParseException">NumberParseException</a>(error_type, msg)<br>
<br>
<a href="builtins.html#Exception">Exception</a> when attempting to parse a putative phone number<br> </tt></td></tr>
<tr><td> </td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="phonenumbers.phonenumberutil.html#NumberParseException">NumberParseException</a></dd>
<dd><a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a></dd>
<dd><a href="builtins.html#Exception">builtins.Exception</a></dd>
<dd><a href="builtins.html#BaseException">builtins.BaseException</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="NumberParseException-__init__"><strong>__init__</strong></a>(self, error_type, msg)</dt><dd><tt>Initialize self. See help(type(self)) for accurate signature.</tt></dd></dl>
<dl><dt><a name="NumberParseException-__reduce__"><strong>__reduce__</strong></a>(self)</dt><dd><tt>Helper for pickle.</tt></dd></dl>
<dl><dt><a name="NumberParseException-__unicode__"><strong>__unicode__</strong></a>(self)</dt></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>INVALID_COUNTRY_CODE</strong> = 0</dl>
<dl><dt><strong>NOT_A_NUMBER</strong> = 1</dl>
<dl><dt><strong>TOO_LONG</strong> = 4</dl>
<dl><dt><strong>TOO_SHORT_AFTER_IDD</strong> = 2</dl>
<dl><dt><strong>TOO_SHORT_NSN</strong> = 3</dl>
<hr>
Methods inherited from <a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a>:<br>
<dl><dt><a name="NumberParseException-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>Return str(self).</tt></dd></dl>
<hr>
Data descriptors inherited from <a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<hr>
Static methods inherited from <a href="builtins.html#Exception">builtins.Exception</a>:<br>
<dl><dt><a name="NumberParseException-__new__"><strong>__new__</strong></a>(*args, **kwargs)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt><dd><tt>Create and return a new <a href="builtins.html#object">object</a>. See help(type) for accurate signature.</tt></dd></dl>
<hr>
Methods inherited from <a href="builtins.html#BaseException">builtins.BaseException</a>:<br>
<dl><dt><a name="NumberParseException-__delattr__"><strong>__delattr__</strong></a>(self, name, /)</dt><dd><tt>Implement delattr(self, name).</tt></dd></dl>
<dl><dt><a name="NumberParseException-__getattribute__"><strong>__getattribute__</strong></a>(self, name, /)</dt><dd><tt>Return getattr(self, name).</tt></dd></dl>
<dl><dt><a name="NumberParseException-__repr__"><strong>__repr__</strong></a>(self, /)</dt><dd><tt>Return repr(self).</tt></dd></dl>
<dl><dt><a name="NumberParseException-__setattr__"><strong>__setattr__</strong></a>(self, name, value, /)</dt><dd><tt>Implement setattr(self, name, value).</tt></dd></dl>
<dl><dt><a name="NumberParseException-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>
<dl><dt><a name="NumberParseException-with_traceback"><strong>with_traceback</strong></a>(...)</dt><dd><tt><a href="builtins.html#Exception">Exception</a>.<a href="#NumberParseException-with_traceback">with_traceback</a>(tb) --<br>
set self.<strong>__traceback__</strong> to tb and return self.</tt></dd></dl>
<hr>
Data descriptors inherited from <a href="builtins.html#BaseException">builtins.BaseException</a>:<br>
<dl><dt><strong>__cause__</strong></dt>
<dd><tt>exception cause</tt></dd>
</dl>
<dl><dt><strong>__context__</strong></dt>
<dd><tt>exception context</tt></dd>
</dl>
<dl><dt><strong>__suppress_context__</strong></dt>
</dl>
<dl><dt><strong>__traceback__</strong></dt>
</dl>
<dl><dt><strong>args</strong></dt>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="PhoneNumberFormat">class <strong>PhoneNumberFormat</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Phone number format.<br>
<br>
INTERNATIONAL and NATIONAL formats are consistent with the definition in<br>
ITU-T Recommendation E123. However we follow local conventions such as using<br>
'-' instead of whitespace as separators. For example, the number of the<br>
Google Switzerland office will be written as "+41 44 668 1800" in<br>
INTERNATIONAL format, and as "044 668 1800" in NATIONAL format. E164 format<br>
is as per INTERNATIONAL format but with no formatting applied,<br>
e.g. "+41446681800". <a href="http://www.rfc-editor.org/rfc/rfc3966.txt">RFC3966</a> is as per INTERNATIONAL format, but with all<br>
spaces and other separating symbols replaced with a hyphen, and with any<br>
phone number extension appended with ";ext=". It also will have a prefix of<br>
"tel:" added, e.g. "tel:+41-44-668-1800".<br>
<br>
Note: If you are considering storing the number in a neutral format, you<br>
are highly advised to use the PhoneNumber class.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Class methods defined here:<br>
<dl><dt><a name="PhoneNumberFormat-to_string"><strong>to_string</strong></a>(val)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt><dd><tt>Return a string representation of a <a href="#PhoneNumberFormat">PhoneNumberFormat</a> value</tt></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>E164</strong> = 0</dl>
<dl><dt><strong>INTERNATIONAL</strong> = 1</dl>
<dl><dt><strong>NATIONAL</strong> = 2</dl>
<dl><dt><strong>RFC3966</strong> = 3</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="PhoneNumberType">class <strong>PhoneNumberType</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Type of phone numbers.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Class methods defined here:<br>
<dl><dt><a name="PhoneNumberType-to_string"><strong>to_string</strong></a>(val)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt><dd><tt>Return a string representation of a <a href="#PhoneNumberType">PhoneNumberType</a> value</tt></dd></dl>
<dl><dt><a name="PhoneNumberType-values"><strong>values</strong></a>()<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>FIXED_LINE</strong> = 0</dl>
<dl><dt><strong>FIXED_LINE_OR_MOBILE</strong> = 2</dl>
<dl><dt><strong>MOBILE</strong> = 1</dl>
<dl><dt><strong>PAGER</strong> = 8</dl>
<dl><dt><strong>PERSONAL_NUMBER</strong> = 7</dl>
<dl><dt><strong>PREMIUM_RATE</strong> = 4</dl>
<dl><dt><strong>SHARED_COST</strong> = 5</dl>
<dl><dt><strong>TOLL_FREE</strong> = 3</dl>
<dl><dt><strong>UAN</strong> = 9</dl>
<dl><dt><strong>UNKNOWN</strong> = 99</dl>
<dl><dt><strong>VOICEMAIL</strong> = 10</dl>
<dl><dt><strong>VOIP</strong> = 6</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="ValidationResult">class <strong>ValidationResult</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Possible outcomes when testing if a PhoneNumber is a possible number.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Class methods defined here:<br>
<dl><dt><a name="ValidationResult-to_string"><strong>to_string</strong></a>(val)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt><dd><tt>Return a string representation of a <a href="#ValidationResult">ValidationResult</a> value</tt></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>INVALID_COUNTRY_CODE</strong> = 1</dl>
<dl><dt><strong>INVALID_LENGTH</strong> = 5</dl>
<dl><dt><strong>IS_POSSIBLE</strong> = 0</dl>
<dl><dt><strong>IS_POSSIBLE_LOCAL_ONLY</strong> = 4</dl>
<dl><dt><strong>TOO_LONG</strong> = 3</dl>
<dl><dt><strong>TOO_SHORT</strong> = 2</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-can_be_internationally_dialled"><strong>can_be_internationally_dialled</strong></a>(numobj)</dt><dd><tt>Returns True if the number can only be dialled from outside the region,<br>
or unknown.<br>
<br>
If the number can only be dialled from within the region<br>
as well, returns False. Does not check the number is a valid number.<br>
Note that, at the moment, this method does not handle short numbers (which<br>
are currently all presumed to not be diallable from outside their country).<br>
<br>
Arguments:<br>
numobj -- the phone number objectfor which we want to know whether it is<br>
diallable from outside the region.</tt></dd></dl>
<dl><dt><a name="-convert_alpha_characters_in_number"><strong>convert_alpha_characters_in_number</strong></a>(number)</dt><dd><tt>Convert alpha chars in a number to their respective digits on a keypad,<br>
but retains existing formatting.</tt></dd></dl>
<dl><dt><a name="-country_code_for_region"><strong>country_code_for_region</strong></a>(region_code)</dt><dd><tt>Returns the country calling code for a specific region.<br>
<br>
For example, this would be 1 for the United States, and 64 for New<br>
Zealand.<br>
<br>
Arguments:<br>
region_code -- The region that we want to get the country calling code for.<br>
<br>
Returns the country calling code for the region denoted by region_code.</tt></dd></dl>
<dl><dt><a name="-country_code_for_valid_region"><strong>country_code_for_valid_region</strong></a>(region_code)</dt><dd><tt>Returns the country calling code for a specific region.<br>
<br>
For example, this would be 1 for the United States, and 64 for New<br>
Zealand. Assumes the region is already valid.<br>
<br>
Arguments:<br>
region_code -- The region that we want to get the country calling code for.<br>
<br>
Returns the country calling code for the region denoted by region_code.</tt></dd></dl>
<dl><dt><a name="-country_mobile_token"><strong>country_mobile_token</strong></a>(country_code)</dt><dd><tt>Returns the mobile token for the provided country calling code if it has one, otherwise<br>
returns an empty string. A mobile token is a number inserted before the area code when dialing<br>
a mobile number from that country from abroad.<br>
<br>
Arguments:<br>
country_code -- the country calling code for which we want the mobile token<br>
Returns the mobile token, as a string, for the given country calling code.</tt></dd></dl>
<dl><dt><a name="-example_number"><strong>example_number</strong></a>(region_code)</dt><dd><tt>Gets a valid number for the specified region.<br>
<br>
Arguments:<br>
region_code -- The region for which an example number is needed.<br>
<br>
Returns a valid fixed-line number for the specified region. Returns None<br>
when the metadata does not contain such information, or the region 001 is<br>
passed in. For 001 (representing non-geographical numbers), call<br>
example_number_for_non_geo_entity instead.</tt></dd></dl>
<dl><dt><a name="-example_number_for_non_geo_entity"><strong>example_number_for_non_geo_entity</strong></a>(country_calling_code)</dt><dd><tt>Gets a valid number for the specified country calling code for a non-geographical entity.<br>
<br>
Arguments:<br>
country_calling_code -- The country calling code for a non-geographical entity.<br>
<br>
Returns a valid number for the non-geographical entity. Returns None when<br>
the metadata does not contain such information, or the country calling<br>
code passed in does not belong to a non-geographical entity.</tt></dd></dl>
<dl><dt><a name="-example_number_for_type"><strong>example_number_for_type</strong></a>(region_code, num_type)</dt><dd><tt>Gets a valid number for the specified region and number type.<br>
<br>
If None is given as the region_code, then the returned number <a href="builtins.html#object">object</a><br>
may belong to any country.<br>
<br>
Arguments:<br>
region_code -- The region for which an example number is needed, or None.<br>
num_type -- The type of number that is needed.<br>
<br>
Returns a valid number for the specified region and type. Returns None<br>
when the metadata does not contain such information or if an invalid<br>
region or region 001 was specified. For 001 (representing<br>
non-geographical numbers), call example_number_for_non_geo_entity instead.</tt></dd></dl>
<dl><dt><a name="-format_by_pattern"><strong>format_by_pattern</strong></a>(numobj, number_format, user_defined_formats)</dt><dd><tt>Formats a phone number using client-defined formatting rules.<br>
<br>
Note that if the phone number has a country calling code of zero or an<br>
otherwise invalid country calling code, we cannot work out things like<br>
whether there should be a national prefix applied, or how to format<br>
extensions, so we return the national significant number with no<br>
formatting applied.<br>
<br>
Arguments:<br>
numobj -- The phone number to be formatted<br>
number_format -- The format the phone number should be formatted into,<br>
as a <a href="#PhoneNumberFormat">PhoneNumberFormat</a> value.<br>
user_defined_formats -- formatting rules specified by clients, as a list<br>
of NumberFormat objects.<br>
<br>
Returns the formatted phone number.</tt></dd></dl>
<dl><dt><a name="-format_in_original_format"><strong>format_in_original_format</strong></a>(numobj, region_calling_from)</dt><dd><tt>Format a number using the original format that the number was parsed from.<br>
<br>
The original format is embedded in the country_code_source field of the<br>
PhoneNumber <a href="builtins.html#object">object</a> passed in. If such information is missing, the number<br>
will be formatted into the NATIONAL format by default.<br>
<br>
When we don't have a formatting pattern for the number, the method<br>
returns the raw input when it is available.<br>
<br>
Note this method guarantees no digit will be inserted, removed or modified<br>
as a result of formatting.<br>
<br>
Arguments:<br>
number -- The phone number that needs to be formatted in its original<br>
number format<br>
region_calling_from -- The region whose IDD needs to be prefixed if the<br>
original number has one.<br>
<br>
Returns the formatted phone number in its original number format.</tt></dd></dl>
<dl><dt><a name="-format_national_number_with_carrier_code"><strong>format_national_number_with_carrier_code</strong></a>(numobj, carrier_code)</dt><dd><tt>Format a number in national format for dialing using the specified carrier.<br>
<br>
The carrier-code will always be used regardless of whether the phone<br>
number already has a preferred domestic carrier code stored. If<br>
carrier_code contains an empty string, returns the number in national<br>
format without any carrier code.<br>
<br>
Arguments:<br>
numobj -- The phone number to be formatted<br>
carrier_code -- The carrier selection code to be used<br>
<br>
Returns the formatted phone number in national format for dialing using<br>
the carrier as specified in the carrier_code.</tt></dd></dl>
<dl><dt><a name="-format_national_number_with_preferred_carrier_code"><strong>format_national_number_with_preferred_carrier_code</strong></a>(numobj, fallback_carrier_code)</dt><dd><tt>Formats a phone number in national format for dialing using the carrier<br>
as specified in the preferred_domestic_carrier_code field of the<br>
PhoneNumber <a href="builtins.html#object">object</a> passed in. If that is missing, use the<br>
fallback_carrier_code passed in instead. If there is no<br>
preferred_domestic_carrier_code, and the fallback_carrier_code contains an<br>
empty string, return the number in national format without any carrier<br>
code.<br>
<br>
Use format_national_number_with_carrier_code instead if the carrier code<br>
passed in should take precedence over the number's<br>
preferred_domestic_carrier_code when formatting.<br>
<br>
Arguments:<br>
numobj -- The phone number to be formatted<br>
carrier_code -- The carrier selection code to be used, if none is found in the<br>
phone number itself.<br>
<br>
Returns the formatted phone number in national format for dialing using<br>
the number's preferred_domestic_carrier_code, or the fallback_carrier_code<br>
pass in if none is found.</tt></dd></dl>
<dl><dt><a name="-format_number"><strong>format_number</strong></a>(numobj, num_format)</dt><dd><tt>Formats a phone number in the specified format using default rules.<br>
<br>
Note that this does not promise to produce a phone number that the user<br>
can dial from where they are - although we do format in either 'national'<br>
or 'international' format depending on what the client asks for, we do not<br>
currently support a more abbreviated format, such as for users in the same<br>
"area" who could potentially dial the number without area code. Note that<br>
if the phone number has a country calling code of 0 or an otherwise<br>
invalid country calling code, we cannot work out which formatting rules to<br>
apply so we return the national significant number with no formatting<br>
applied.<br>
<br>
Arguments:<br>
numobj -- The phone number to be formatted.<br>
num_format -- The format the phone number should be formatted into<br>
<br>
Returns the formatted phone number.</tt></dd></dl>
<dl><dt><a name="-format_number_for_mobile_dialing"><strong>format_number_for_mobile_dialing</strong></a>(numobj, region_calling_from, with_formatting)</dt><dd><tt>Returns a number formatted in such a way that it can be dialed from a<br>
mobile phone in a specific region.<br>
<br>
If the number cannot be reached from the region (e.g. some countries block<br>
toll-free numbers from being called outside of the country), the method<br>
returns an empty string.<br>
<br>
Arguments:<br>
numobj -- The phone number to be formatted<br>
region_calling_from -- The region where the call is being placed.<br>
<br>
with_formatting -- whether the number should be returned with formatting<br>
symbols, such as spaces and dashes.<br>
<br>
Returns the formatted phone number.</tt></dd></dl>
<dl><dt><a name="-format_out_of_country_calling_number"><strong>format_out_of_country_calling_number</strong></a>(numobj, region_calling_from)</dt><dd><tt>Formats a phone number for out-of-country dialing purposes.<br>
<br>
If no region_calling_from is supplied, we format the number in its<br>
INTERNATIONAL format. If the country calling code is the same as that of<br>
the region where the number is from, then NATIONAL formatting will be<br>
applied.<br>
<br>
If the number itself has a country calling code of zero or an otherwise<br>
invalid country calling code, then we return the number with no formatting<br>
applied.<br>
<br>
Note this function takes care of the case for calling inside of NANPA and<br>
between Russia and Kazakhstan (who share the same country calling<br>
code). In those cases, no international prefix is used. For regions which<br>
have multiple international prefixes, the number in its INTERNATIONAL<br>
format will be returned instead.<br>
<br>
Arguments:<br>
numobj -- The phone number to be formatted<br>
region_calling_from -- The region where the call is being placed<br>
<br>
Returns the formatted phone number</tt></dd></dl>
<dl><dt><a name="-format_out_of_country_keeping_alpha_chars"><strong>format_out_of_country_keeping_alpha_chars</strong></a>(numobj, region_calling_from)</dt><dd><tt>Formats a phone number for out-of-country dialing purposes.<br>
<br>
Note that in this version, if the number was entered originally using<br>
alpha characters and this version of the number is stored in raw_input,<br>
this representation of the number will be used rather than the digit<br>
representation. Grouping information, as specified by characters such as<br>
"-" and " ", will be retained.<br>
<br>
Caveats:<br>
<br>
- This will not produce good results if the country calling code is both<br>
present in the raw input _and_ is the start of the national<br>
number. This is not a problem in the regions which typically use alpha<br>
numbers.<br>
<br>
- This will also not produce good results if the raw input has any<br>
grouping information within the first three digits of the national<br>
number, and if the function needs to strip preceding digits/words in<br>
the raw input before these digits. Normally people group the first<br>
three digits together so this is not a huge problem - and will be fixed<br>
if it proves to be so.<br>
<br>
Arguments:<br>
numobj -- The phone number that needs to be formatted.<br>
region_calling_from -- The region where the call is being placed.<br>
<br>
Returns the formatted phone number</tt></dd></dl>
<dl><dt><a name="-invalid_example_number"><strong>invalid_example_number</strong></a>(region_code)</dt><dd><tt>Gets an invalid number for the specified region.<br>
<br>
This is useful for unit-testing purposes, where you want to test what<br>
will happen with an invalid number. Note that the number that is<br>
returned will always be able to be parsed and will have the correct<br>
country code. It may also be a valid *short* number/code for this<br>
region. Validity checking such numbers is handled with shortnumberinfo.<br>
<br>
Arguments:<br>
region_code -- The region for which an example number is needed.<br>
<br>
<br>
Returns an invalid number for the specified region. Returns None when an<br>
unsupported region or the region 001 (Earth) is passed in.</tt></dd></dl>
<dl><dt><a name="-is_alpha_number"><strong>is_alpha_number</strong></a>(number)</dt><dd><tt>Checks if the number is a valid vanity (alpha) number such as 800<br>
MICROSOFT. A valid vanity number will start with at least 3 digits and<br>
will have three or more alpha characters. This does not do region-specific<br>
checks - to work out if this number is actually valid for a region, it<br>
should be parsed and methods such as <a href="#-is_possible_number_with_reason">is_possible_number_with_reason</a>() and<br>
<a href="#-is_valid_number">is_valid_number</a>() should be used.<br>
<br>
Arguments:<br>
number -- the number that needs to be checked<br>
<br>
Returns True if the number is a valid vanity number</tt></dd></dl>
<dl><dt><a name="-is_mobile_number_portable_region"><strong>is_mobile_number_portable_region</strong></a>(region_code)</dt><dd><tt>Returns true if the supplied region supports mobile number portability.<br>
Returns false for invalid, unknown or regions that don't support mobile<br>
number portability.<br>
<br>
Arguments:<br>
region_code -- the region for which we want to know whether it supports mobile number<br>
portability or not.</tt></dd></dl>
<dl><dt><a name="-is_nanpa_country"><strong>is_nanpa_country</strong></a>(region_code)</dt><dd><tt>Checks if this region is a NANPA region.<br>
<br>
Returns True if region_code is one of the regions under the North American<br>
Numbering Plan Administration (NANPA).</tt></dd></dl>
<dl><dt><a name="-is_number_geographical"><strong>is_number_geographical</strong></a>(numobj)</dt><dd><tt>Tests whether a phone number has a geographical association.<br>
<br>
It checks if the number is associated with a certain region in the country<br>
to which it belongs. Note that this doesn't verify if the number is<br>
actually in use.<br>
country_code -- the country calling code for which we want the mobile token</tt></dd></dl>
<dl><dt><a name="-is_number_match"><strong>is_number_match</strong></a>(num1, num2)</dt><dd><tt>Takes two phone numbers and compares them for equality.<br>
<br>
For example, the numbers +1 345 657 1234 and 657 1234 are a SHORT_NSN_MATCH.<br>
The numbers +1 345 657 1234 and 345 657 are a NO_MATCH.<br>
<br>
Arguments<br>
num1 -- First number <a href="builtins.html#object">object</a> or string to compare. Can contain formatting,<br>
and can have country calling code specified with + at the start.<br>
num2 -- Second number <a href="builtins.html#object">object</a> or string to compare. Can contain formatting,<br>
and can have country calling code specified with + at the start.<br>
<br>
Returns:<br>
- EXACT_MATCH if the country_code, NSN, presence of a leading zero for<br>
Italian numbers and any extension present are the same.<br>
- NSN_MATCH if either or both has no region specified, and the NSNs and<br>
extensions are the same.<br>
- SHORT_NSN_MATCH if either or both has no region specified, or the<br>
region specified is the same, and one NSN could be a shorter version of<br>
the other number. This includes the case where one has an extension<br>
specified, and the other does not.<br>
- NO_MATCH otherwise.</tt></dd></dl>
<dl><dt><a name="-is_number_type_geographical"><strong>is_number_type_geographical</strong></a>(num_type, country_code)</dt><dd><tt>Tests whether a phone number has a geographical association,<br>
as represented by its type and the country it belongs to.<br>
<br>
This version of isNumberGeographical exists since calculating the phone<br>
number type is expensive; if we have already done this, we don't want to<br>
do it again.</tt></dd></dl>
<dl><dt><a name="-is_possible_number"><strong>is_possible_number</strong></a>(numobj)</dt><dd><tt>Convenience wrapper around is_possible_number_with_reason.<br>
<br>
Instead of returning the reason for failure, this method returns true if<br>
the number is either a possible fully-qualified number (containing the area<br>
code and country code), or if the number could be a possible local number<br>
(with a country code, but missing an area code). Local numbers are<br>
considered possible if they could be possibly dialled in this format: if<br>
the area code is needed for a call to connect, the number is not considered<br>
possible without it.<br>
<br>
Arguments:<br>
numobj -- the number <a href="builtins.html#object">object</a> that needs to be checked<br>
<br>
Returns True if the number is possible</tt></dd></dl>
<dl><dt><a name="-is_possible_number_for_type"><strong>is_possible_number_for_type</strong></a>(numobj, numtype)</dt><dd><tt>Convenience wrapper around is_possible_number_for_type_with_reason.<br>
<br>
Instead of returning the reason for failure, this method returns true if<br>
the number is either a possible fully-qualified number (containing the area<br>
code and country code), or if the number could be a possible local number<br>
(with a country code, but missing an area code). Local numbers are<br>
considered possible if they could be possibly dialled in this format: if<br>
the area code is needed for a call to connect, the number is not considered<br>
possible without it.<br>
<br>
Arguments:<br>
numobj -- the number <a href="builtins.html#object">object</a> that needs to be checked<br>
numtype -- the type we are interested in<br>
<br>
Returns True if the number is possible</tt></dd></dl>
<dl><dt><a name="-is_possible_number_for_type_with_reason"><strong>is_possible_number_for_type_with_reason</strong></a>(numobj, numtype)</dt><dd><tt>Check whether a phone number is a possible number of a particular type.<br>
<br>
For types that don't exist in a particular region, this will return a result<br>
that isn't so useful; it is recommended that you use<br>
supported_types_for_region or supported_types_for_non_geo_entity<br>
respectively before calling this method to determine whether you should call<br>
it for this number at all.<br>
<br>
This provides a more lenient check than is_valid_number in the following sense:<br>
<br>
- It only checks the length of phone numbers. In particular, it doesn't<br>
check starting digits of the number.<br>
<br>
- For some numbers (particularly fixed-line), many regions have the<br>
concept of area code, which together with subscriber number constitute<br>
the national significant number. It is sometimes okay to dial only the<br>
subscriber number when dialing in the same area. This function will<br>
return IS_POSSIBLE_LOCAL_ONLY if the subscriber-number-only version is<br>
passed in. On the other hand, because is_valid_number validates using<br>
information on both starting digits (for fixed line numbers, that would<br>
most likely be area codes) and length (obviously includes the length of<br>
area codes for fixed line numbers), it will return false for the<br>
subscriber-number-only version.<br>
<br>
Arguments:<br>
numobj -- The number <a href="builtins.html#object">object</a> that needs to be checked<br>
numtype -- The type we are interested in<br>
<br>
Returns a value from <a href="#ValidationResult">ValidationResult</a> which indicates whether the number<br>
is possible</tt></dd></dl>
<dl><dt><a name="-is_possible_number_string"><strong>is_possible_number_string</strong></a>(number, region_dialing_from)</dt><dd><tt>Check whether a phone number string is a possible number.<br>
<br>
Takes a number in the form of a string, and the region where the number<br>
could be dialed from. It provides a more lenient check than<br>
is_valid_number; see <a href="#-is_possible_number_with_reason">is_possible_number_with_reason</a>() for details.<br>
<br>
This method first parses the number, then invokes is_possible_number with<br>
the resultant PhoneNumber <a href="builtins.html#object">object</a>.<br>
<br>
Arguments:<br>
number -- The number that needs to be checked, in the form of a string.<br>
region_dialling_from -- The region that we are expecting the number to be<br>
dialed from. Note this is different from the region where the<br>
number belongs. For example, the number +1 650 253 0000 is a<br>
number that belongs to US. When written in this form, it can be<br>
dialed from any region. When it is written as 00 1 650 253 0000,<br>
it can be dialed from any region which uses an international<br>
dialling prefix of 00. When it is written as 650 253 0000, it<br>
can only be dialed from within the US, and when written as 253<br>
0000, it can only be dialed from within a smaller area in the US<br>
(Mountain View, CA, to be more specific).<br>
<br>
Returns True if the number is possible</tt></dd></dl>
<dl><dt><a name="-is_possible_number_with_reason"><strong>is_possible_number_with_reason</strong></a>(numobj)</dt></dl>
<dl><dt><a name="-is_valid_number"><strong>is_valid_number</strong></a>(numobj)</dt><dd><tt>Tests whether a phone number matches a valid pattern.<br>
<br>
Note this doesn't verify the number is actually in use, which is<br>
impossible to tell by just looking at a number itself. It only verifies<br>
whether the parsed, canonicalised number is valid: not whether a<br>
particular series of digits entered by the user is diallable from the<br>
region provided when parsing. For example, the number +41 (0) 78 927 2696<br>
can be parsed into a number with country code "41" and national<br>
significant number "789272696". This is valid, while the original string<br>
is not diallable.<br>
<br>
Arguments:<br>
numobj -- The phone number <a href="builtins.html#object">object</a> that we want to validate<br>
<br>
Returns a boolean that indicates whether the number is of a valid pattern.</tt></dd></dl>
<dl><dt><a name="-is_valid_number_for_region"><strong>is_valid_number_for_region</strong></a>(numobj, region_code)</dt><dd><tt>Tests whether a phone number is valid for a certain region.<br>
<br>
Note this doesn't verify the number is actually in use, which is<br>
impossible to tell by just looking at a number itself. If the country<br>
calling code is not the same as the country calling code for the region,<br>
this immediately exits with false. After this, the specific number pattern<br>
rules for the region are examined. This is useful for determining for<br>
example whether a particular number is valid for Canada, rather than just<br>
a valid NANPA number.<br>
<br>
Warning: In most cases, you want to use is_valid_number instead. For<br>
example, this method will mark numbers from British Crown dependencies<br>
such as the Isle of Man as invalid for the region "GB" (United Kingdom),<br>
since it has its own region code, "IM", which may be undesirable.<br>
<br>
Arguments:<br>
numobj -- The phone number <a href="builtins.html#object">object</a> that we want to validate.<br>
region_code -- The region that we want to validate the phone number for.<br>
<br>
Returns a boolean that indicates whether the number is of a valid pattern.</tt></dd></dl>
<dl><dt><a name="-length_of_geographical_area_code"><strong>length_of_geographical_area_code</strong></a>(numobj)</dt><dd><tt>Return length of the geographical area code for a number.<br>
<br>
Gets the length of the geographical area code from the PhoneNumber <a href="builtins.html#object">object</a><br>
passed in, so that clients could use it to split a national significant<br>
number into geographical area code and subscriber number. It works in such<br>
a way that the resultant subscriber number should be diallable, at least<br>
on some devices. An example of how this could be used:<br>
<br>
>>> import phonenumbers<br>
>>> numobj = phonenumbers.<a href="#-parse">parse</a>("16502530000", "US")<br>
>>> nsn = phonenumbers.<a href="#-national_significant_number">national_significant_number</a>(numobj)<br>
>>> ac_len = phonenumbers.<a href="#-length_of_geographical_area_code">length_of_geographical_area_code</a>(numobj)<br>
>>> if ac_len > 0:<br>
... area_code = nsn[:ac_len]<br>
... subscriber_number = nsn[ac_len:]<br>
... else:<br>
... area_code = ""<br>
... subscriber_number = nsn<br>
<br>
N.B.: area code is a very ambiguous concept, so the I18N team generally<br>
recommends against using it for most purposes, but recommends using the<br>
more general national_number instead. Read the following carefully before<br>
deciding to use this method:<br>
<br>
- geographical area codes change over time, and this method honors those<br>
changes; therefore, it doesn't guarantee the stability of the result it<br>
produces.<br>
- subscriber numbers may not be diallable from all devices (notably<br>
mobile devices, which typically require the full national_number to be<br>
dialled in most countries).<br>
- most non-geographical numbers have no area codes, including numbers<br>
from non-geographical entities.<br>
- some geographical numbers have no area codes.<br>
<br>
Arguments:<br>
numobj -- The PhoneNumber <a href="builtins.html#object">object</a> to find the length of the area code form.<br>
<br>
Returns the length of area code of the PhoneNumber <a href="builtins.html#object">object</a> passed in.</tt></dd></dl>
<dl><dt><a name="-length_of_national_destination_code"><strong>length_of_national_destination_code</strong></a>(numobj)</dt><dd><tt>Return length of the national destination code code for a number.<br>
<br>
Gets the length of the national destination code (NDC) from the<br>
PhoneNumber <a href="builtins.html#object">object</a> passed in, so that clients could use it to split a<br>
national significant number into NDC and subscriber number. The NDC of a<br>
phone number is normally the first group of digit(s) right after the<br>
country calling code when the number is formatted in the international<br>
format, if there is a subscriber number part that follows.<br>
<br>
N.B.: similar to an area code, not all numbers have an NDC!<br>
<br>
An example of how this could be used:<br>
<br>
>>> import phonenumbers<br>
>>> numobj = phonenumbers.<a href="#-parse">parse</a>("18002530000", "US")<br>
>>> nsn = phonenumbers.<a href="#-national_significant_number">national_significant_number</a>(numobj)<br>
>>> ndc_len = phonenumbers.<a href="#-length_of_national_destination_code">length_of_national_destination_code</a>(numobj)<br>
>>> if ndc_len > 0:<br>
... national_destination_code = nsn[:ndc_len]<br>
... subscriber_number = nsn[ndc_len:]<br>
... else:<br>
... national_destination_code = ""<br>
... subscriber_number = nsn<br>
<br>
Refer to the unittests to see the difference between this function and<br>
length_of_geographical_area_code.<br>
<br>
Arguments:<br>
numobj -- The PhoneNumber <a href="builtins.html#object">object</a> to find the length of the NDC from.<br>
<br>
Returns the length of NDC of the PhoneNumber <a href="builtins.html#object">object</a> passed in, which<br>
could be zero.</tt></dd></dl>
<dl><dt><a name="-national_significant_number"><strong>national_significant_number</strong></a>(numobj)</dt><dd><tt>Gets the national significant number of a phone number.<br>
<br>
Note that a national significant number doesn't contain a national prefix<br>
or any formatting.<br>
<br>
Arguments:<br>
numobj -- The PhoneNumber <a href="builtins.html#object">object</a> for which the national significant number<br>
is needed.<br>
<br>
Returns the national significant number of the PhoneNumber <a href="builtins.html#object">object</a> passed<br>
in.</tt></dd></dl>
<dl><dt><a name="-ndd_prefix_for_region"><strong>ndd_prefix_for_region</strong></a>(region_code, strip_non_digits)</dt><dd><tt>Returns the national dialling prefix for a specific region.<br>
<br>
For example, this would be 1 for the United States, and 0 for New<br>
Zealand. Set strip_non_digits to True to strip symbols like "~" (which<br>
indicates a wait for a dialling tone) from the prefix returned. If no<br>
national prefix is present, we return None.<br>
<br>
Warning: Do not use this method for do-your-own formatting - for some<br>
regions, the national dialling prefix is used only for certain types of<br>
numbers. Use the library's formatting functions to prefix the national<br>
prefix when required.<br>
<br>
Arguments:<br>
region_code -- The region that we want to get the dialling prefix for.<br>
strip_non_digits -- whether to strip non-digits from the national<br>
dialling prefix.<br>
<br>
Returns the dialling prefix for the region denoted by region_code.</tt></dd></dl>
<dl><dt><a name="-normalize_diallable_chars_only"><strong>normalize_diallable_chars_only</strong></a>(number)</dt><dd><tt>Normalizes a string of characters representing a phone number.<br>
<br>
This strips all characters which are not diallable on a mobile phone<br>
keypad (including all non-ASCII digits).<br>
<br>
Arguments:<br>
number -- a string of characters representing a phone number<br>
<br>
Returns the normalized string version of the phone number.</tt></dd></dl>
<dl><dt><a name="-normalize_digits_only"><strong>normalize_digits_only</strong></a>(number, keep_non_digits=False)</dt><dd><tt>Normalizes a string of characters representing a phone number.<br>
<br>
This converts wide-ascii and arabic-indic numerals to European numerals,<br>
and strips punctuation and alpha characters (optional).<br>
<br>
Arguments:<br>
number -- a string representing a phone number<br>
keep_non_digits -- whether to keep non-digits<br>
<br>
Returns the normalized string version of the phone number.</tt></dd></dl>
<dl><dt><a name="-number_type"><strong>number_type</strong></a>(numobj)</dt><dd><tt>Gets the type of a valid phone number.<br>
<br>
Arguments:<br>
numobj -- The PhoneNumber <a href="builtins.html#object">object</a> that we want to know the type of.<br>
<br>
Returns the type of the phone number, as a <a href="#PhoneNumberType">PhoneNumberType</a> value;<br>
returns <a href="#PhoneNumberType">PhoneNumberType</a>.UNKNOWN if it is invalid.</tt></dd></dl>
<dl><dt><a name="-parse"><strong>parse</strong></a>(number, region=None, keep_raw_input=False, numobj=None, _check_region=True)</dt><dd><tt>Parse a string and return a corresponding PhoneNumber <a href="builtins.html#object">object</a>.<br>
<br>
The method is quite lenient and looks for a number in the input text<br>
(raw input) and does not check whether the string is definitely only a<br>
phone number. To do this, it ignores punctuation and white-space, as<br>
well as any text before the number (e.g. a leading "Tel: ") and trims<br>
the non-number bits. It will accept a number in any format (E164,<br>
national, international etc), assuming it can be interpreted with the<br>
defaultRegion supplied. It also attempts to convert any alpha characters<br>
into digits if it thinks this is a vanity number of the type "1800<br>
MICROSOFT".<br>
<br>
This method will throw a <a href="#NumberParseException">NumberParseException</a> if the number is not<br>
considered to be a possible number. Note that validation of whether the<br>
number is actually a valid number for a particular region is not<br>
performed. This can be done separately with is_valid_number.<br>
<br>
Note this method canonicalizes the phone number such that different<br>
representations can be easily compared, no matter what form it was<br>
originally entered in (e.g. national, international). If you want to<br>
record context about the number being parsed, such as the raw input that<br>
was entered, how the country code was derived etc. then ensure<br>
keep_raw_input is set.<br>
<br>
Note if any new field is added to this method that should always be filled<br>
in, even when keep_raw_input is False, it should also be handled in the<br>
_copy_core_fields_only() function.<br>
<br>
Arguments:<br>
number -- The number that we are attempting to parse. This can<br>
contain formatting such as +, ( and -, as well as a phone<br>
number extension. It can also be provided in <a href="http://www.rfc-editor.org/rfc/rfc3966.txt">RFC3966</a> format.<br>
region -- The region that we are expecting the number to be from. This<br>
is only used if the number being parsed is not written in<br>
international format. The country_code for the number in<br>
this case would be stored as that of the default region<br>
supplied. If the number is guaranteed to start with a '+'<br>
followed by the country calling code, then None or<br>
UNKNOWN_REGION can be supplied.<br>
keep_raw_input -- Whether to populate the raw_input field of the<br>
PhoneNumber <a href="builtins.html#object">object</a> with number (as well as the<br>
country_code_source field).<br>
numobj -- An optional existing PhoneNumber <a href="builtins.html#object">object</a> to receive the<br>
parsing results<br>
_check_region -- Whether to check the supplied region parameter;<br>
should always be True for external callers.<br>
<br>
Returns a PhoneNumber <a href="builtins.html#object">object</a> filled with the parse number.<br>
<br>
Raises:<br>
<a href="#NumberParseException">NumberParseException</a> if the string is not considered to be a viable<br>
phone number (e.g. too few or too many digits) or if no default<br>
region was supplied and the number is not in international format<br>
(does not start with +).</tt></dd></dl>
<dl><dt><a name="-region_code_for_country_code"><strong>region_code_for_country_code</strong></a>(country_code)</dt><dd><tt>Returns the region code that matches a specific country calling code.<br>
<br>
In the case of no region code being found, UNKNOWN_REGION ('ZZ') will be<br>
returned. In the case of multiple regions, the one designated in the<br>
metadata as the "main" region for this calling code will be returned. If<br>
the country_code entered is valid but doesn't match a specific region<br>
(such as in the case of non-geographical calling codes like 800) the value<br>
"001" will be returned (corresponding to the value for World in the UN<br>
M.49 schema).</tt></dd></dl>
<dl><dt><a name="-region_code_for_number"><strong>region_code_for_number</strong></a>(numobj)</dt><dd><tt>Returns the region where a phone number is from.<br>
<br>
This could be used for geocoding at the region level. Only guarantees<br>
correct results for valid, full numbers (not short-codes, or invalid<br>
numbers).<br>
<br>
Arguments:<br>
numobj -- The phone number <a href="builtins.html#object">object</a> whose origin we want to know<br>
<br>
Returns the region where the phone number is from, or None if no region<br>
matches this calling code.</tt></dd></dl>
<dl><dt><a name="-region_codes_for_country_code"><strong>region_codes_for_country_code</strong></a>(country_code)</dt><dd><tt>Returns a list with the region codes that match the specific country calling code.<br>
<br>
For non-geographical country calling codes, the region code 001 is<br>
returned. Also, in the case of no region code being found, an empty<br>
list is returned.</tt></dd></dl>
<dl><dt><a name="-supported_calling_codes"><strong>supported_calling_codes</strong></a>()</dt><dd><tt>Returns all country calling codes the library has metadata for, covering<br>
both non-geographical entities (global network calling codes) and those<br>
used for geographical entities. This could be used to populate a drop-down<br>
box of country calling codes for a phone-number widget, for instance.<br>
<br>
Returns an unordered set of the country calling codes for every geographica<br>
and non-geographical entity the library supports.</tt></dd></dl>
<dl><dt><a name="-supported_types_for_non_geo_entity"><strong>supported_types_for_non_geo_entity</strong></a>(country_code)</dt><dd><tt>Returns the types for a country-code belonging to a non-geographical entity<br>
which the library has metadata for. Will not include FIXED_LINE_OR_MOBILE<br>
(if numbers for this non-geographical entity could be classified as<br>
FIXED_LINE_OR_MOBILE, both FIXED_LINE and MOBILE would be present) and<br>
UNKNOWN.<br>
<br>
No types will be returned for country calling codes that do not map to a<br>
known non-geographical entity.</tt></dd></dl>
<dl><dt><a name="-supported_types_for_region"><strong>supported_types_for_region</strong></a>(region_code)</dt><dd><tt>Returns the types for a given region which the library has metadata for.<br>
<br>
Will not include FIXED_LINE_OR_MOBILE (if numbers in this region could<br>
be classified as FIXED_LINE_OR_MOBILE, both FIXED_LINE and MOBILE would<br>
be present) and UNKNOWN.<br>
<br>
No types will be returned for invalid or unknown region codes.</tt></dd></dl>
<dl><dt><a name="-truncate_too_long_number"><strong>truncate_too_long_number</strong></a>(numobj)</dt><dd><tt>Truncate a number <a href="builtins.html#object">object</a> that is too long.<br>
<br>
Attempts to extract a valid number from a phone number that is too long<br>
to be valid, and resets the PhoneNumber <a href="builtins.html#object">object</a> passed in to that valid<br>
version. If no valid number could be extracted, the PhoneNumber <a href="builtins.html#object">object</a><br>
passed in will not be modified.<br>
<br>
Arguments:<br>
numobj -- A PhoneNumber <a href="builtins.html#object">object</a> which contains a number that is too long to<br>
be valid.<br>
<br>
Returns True if a valid phone number can be successfully extracted.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>COUNTRY_CODES_FOR_NON_GEO_REGIONS</strong> = {800, 808, 870, 878, 881, 882, ...}<br>
<strong>COUNTRY_CODE_TO_REGION_CODE</strong> = {1: ('US', 'AG', 'AI', 'AS', 'BB', 'BM', 'BS', 'CA', 'DM', 'DO', 'GD', 'GU', 'JM', 'KN', 'KY', 'LC', 'MP', 'MS', 'PR', 'SX', ...), 7: ('RU', 'KZ'), 20: ('EG',), 27: ('ZA',), 30: ('GR',), 31: ('NL',), 32: ('BE',), 33: ('FR',), 34: ('ES',), 36: ('HU',), ...}<br>
<strong>NON_DIGITS_PATTERN</strong> = re.compile('(?:\\D+)')<br>
<strong>REGION_CODE_FOR_NON_GEO_ENTITY</strong> = '001'<br>
<strong>SUPPORTED_REGIONS</strong> = {'AC', 'AD', 'AE', 'AF', 'AG', 'AI', ...}<br>
<strong>UNKNOWN_REGION</strong> = 'ZZ'<br>
<strong>U_DASH</strong> = '-'<br>
<strong>U_EMPTY_STRING</strong> = ''<br>
<strong>U_SEMICOLON</strong> = ';'<br>
<strong>U_SPACE</strong> = ' '<br>
<strong>U_TILDE</strong> = '~'<br>
<strong>U_ZERO</strong> = '0'</td></tr></table>
</body></html>
|