How to match zipcodes?

US Postal Codes

Example: 98102 or 98102-1234

Regex: ^[0-9]{5}(?:-[0-9]{4})?$

UK Postal Code

Example: WC2N 5DU

Regex: ^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$

Canadian Postal Code

Example: A1A 1A1

Regex: ^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$



×

Subscribe

The latest tutorials sent straight to your inbox.