Reputation: 15148
i need a regEx in which 4 or 5 digits are okay (for german, austrian or switzerland ZIP).
Please help
Upvotes: 1
Views: 2132
Reputation: 7468
This will match valid Swiss or German Postal Codes (Swiss are from 1000 - 9999, German from 00000 - 99999):
^(?:[1-9]\d{3}|\d{5})$
Upvotes: 1
Reputation: 38128
A simple one would be (assuming Perl compatible regular expressions)
^(\d{4,5})$
You would still want to validate that it is an actual valid value afterwards (for example, you don't say whether leading zeroes are valid)
Upvotes: 1
Reputation: 213115
^\d{4,5}$
However, this gives you no guarantee whether they really exist.
Upvotes: 3