Python (re)

International Phone (E.164) in PY

Validate phone numbers in ITU-T E.164 international format: a + sign followed by 2–15 digits, first digit non-zero.

Try it in the PY tester →

Pattern

regexPY
^\+[1-9]\d{1,14}$

Python (re) code

pyPython
import re

pattern = re.compile(r"^\+[1-9]\d{1,14}$")
input_text = "+14155552671"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

How the pattern works

^ anchors the start. \+ matches the required leading plus sign. [1-9] ensures the country code starts with a non-zero digit. \d{1,14} allows 1 to 14 additional digits for a total of 2–15 digits after the +, per E.164 spec. $ anchors the end.

Examples

Input

+14155552671

Matches

  • +14155552671

Input

+442071838750

Matches

  • +442071838750

Input

14155552671

No match

Same pattern, other engines

← Back to International Phone (E.164) overview (all engines)