regexzipcodepostal-code

What is the ultimate postal code and zip regex?


I'm looking for the ultimate postal code and zip code regex. I'm looking for something that will cover most (hopefully all) of the world.


Solution

  • There is none.

    Postal/zip codes around the world don't follow a common pattern. In some countries they are made up by numbers, in others they can be combinations of numbers an letters, some can contain spaces, others dots, the number of characters can vary from two to at least six...

    What you could do (theoretically) is create a seperate regex for every country in the world, not recommendable IMO. But you would still be missing on the validation part: Zip code 12345 may exist, but 12346 not, maybe 12344 doesn't exist either. How do you check for that with a regex?

    You can't.