German Phone Number Regex for Go
/^(?:\+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 Go. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.
Go Implementation
// German Phone Number
// ReDoS-safe | RegexVault — Localization > Phone Numbers
package validation
import "regexp"
var germanPhoneNumberRe = regexp.MustCompile(`^(?:\+49[\s.-]?|0)(?:[1-9][0-9]{1,4})[\s.-]?[0-9]{5,10}$`)
func ValidateGermanPhoneNumber(s string) bool {
return germanPhoneNumberRe.MatchString(s)
}
// Example
// fmt.Println(ValidateGermanPhoneNumber("+49 30 12345678")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
+49 30 12345678 | +49 0 12345678 |
030 12345678 | 00 12345678 |
+4915123456789 | +44 30 12345678 |
015123456789 | 030 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 Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. 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