REGEXVAULTv2.0
Localization/Phone Numbers
Verified Safe

German Phone Number Regex for PHP

/^(?:\+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 PHP. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.

Php Implementation

Php
<?php
// German Phone Number
// ReDoS-safe | RegexVault — Localization > Phone Numbers

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

function validate_german_phone_number(string $input): bool {
    return (bool) preg_match(GERMAN_PHONE_NUMBER_PATTERN, $input);
}

// Example
var_dump(validate_german_phone_number("+49 30 12345678")); // bool(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 PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. 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