Regex for Japanese Postal Code
Regex Pattern
^\d{3}-\d{4}$Japanese postal code (XXX-XXXX)
Quick Answer
The regex pattern for japanese postal code is `^\d{3}-\d{4}$`. Japanese postal code (XXX-XXXX). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| 100-0001 | ✓ Matches |
| 160-0023 | ✓ Matches |
| 530-0001 | ✓ Matches |
| 1000001 | ✗ No match |
| 12-3456 | ✗ No match |
| 100-001 | ✗ No match |
Code Examples
javascript
const regex = /^\d{3}-\d{4}$/;
const isValid = regex.test(value);python
import re
pattern = r'^\d{3}-\d{4}$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^\d{3}-\d{4}$/
if value =~ pattern
puts "valid"
endphp
if (preg_match('/^\d{3}-\d{4}$/', $value)) {
echo "valid";
}java
String pattern = "^\\d{3}-\\d{4}$";
boolean isValid = value.matches(pattern);