DD
DevDash

Regex for German Postal Code

Regex Pattern

^\d{5}$

German postal code — exactly 5 digits

Quick Answer

The regex pattern for german postal code is `^\d{5}$`. German postal code — exactly 5 digits. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
10115✓ Matches
80331✓ Matches
20095✓ Matches
1234✗ No match
123456✗ No match
ABCDE✗ No match

Code Examples

javascript

const regex = /^\d{5}$/;
const isValid = regex.test(value);

python

import re
pattern = r'^\d{5}$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^\d{5}$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^\d{5}$/', $value)) {
    echo "valid";
}

java

String pattern = "^\\d{5}$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.