REGEXVAULTv2.0
Localization/Phone Numbers
Verified Safe

German Phone Number Regex for Python

/^(?:\+49[\s.-]?|0)(?:[1-9][0-9]{1,4})[\s.-]?[0-9]{5,10}$/

What this pattern does

This page provides a well-structured, multi-part regular expression for matching german phone number, ported and verified for Python. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.

Python Implementation

Python
# German Phone Number
# ReDoS-safe | RegexVault — Localization > Phone Numbers

import re

german_phone_number_pattern = re.compile(r'^(?:\+49[\s.-]?|0)(?:[1-9][0-9]{1,4})[\s.-]?[0-9]{5,10}$')

def validate_german_phone_number(value: str) -> bool:
    return bool(german_phone_number_pattern.fullmatch(value))

# Example
print(validate_german_phone_number("+49 30 12345678"))  # True

Test Cases

Matches (Valid)
Rejects (Invalid)
+49 30 12345678+49 0 12345678
030 1234567800 12345678
+4915123456789+44 30 12345678
015123456789030 1234
+49 89 1234567

When to use this pattern

This pattern is drawn from the Localization > Phone Numbers category and carries a ReDoS-safe certification. That matters for Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

German phone numbers have variable lengths depending on the area code — rural areas have longer area codes and shorter subscriber numbers. Total digits in Germany are 10-11 (excluding country code).

Technical Notes

German area codes range from 1 (national services) to 9 (various regions). Mobile numbers start with 015, 016, or 017. Berlin is 030, Munich is 089, Hamburg is 040. Numbers vary in total length (10-11 digits).

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern